aboutsummaryrefslogtreecommitdiff
path: root/lib/Object/Groupware/Event.pm
blob: 52fa143c7b4ad0377891d73737c27ec5f63b04df (plain)
  1. use v5.36;
  2. use Feature::Compat::Class 0.07;
  3. package Object::Groupware::Event 0.01;
  4. class Object::Groupware::Event;
  5. use utf8;
  6. use Log::Any qw( );
  7. use Feature::Compat::Try;
  8. field $log = Log::Any->get_logger;
  9. field $entry : param;
  10. field $begin : reader = $entry->start;
  11. field $date_begin : reader = $begin->strftime('%A %e. %B');
  12. field $time_begin : reader = $begin->strftime('%k.%M');
  13. field $end : reader = $entry->end;
  14. field $date_end : reader;
  15. field $time_end : reader;
  16. field $datespan : reader;
  17. field $timespan : reader;
  18. field $time_brief : reader;
  19. field $summary : reader = $entry->summary;
  20. field $description : reader = $entry->description;
  21. field $location : reader = $entry->_simple_property('location');
  22. field $price : reader;
  23. field @attendees;
  24. field @attachments;
  25. ADJUST {
  26. if ( defined $end ) {
  27. $date_end = $end->strftime('%A %e. %B');
  28. $time_end = $end->strftime('%k.%M');
  29. }
  30. $datespan
  31. = ( defined $end and $date_end ne $date_begin )
  32. ? ucfirst("$date_begin - $date_end")
  33. : ucfirst("$date_begin");
  34. $timespan
  35. = ( defined $end and not $entry->all_day )
  36. ? ucfirst("$date_begin kl. $time_begin-$time_end")
  37. : undef;
  38. $time_brief
  39. = $entry->all_day
  40. ? $datespan
  41. : ucfirst("$date_begin kl. $time_begin");
  42. $description =~ s/\n\n[Pp]ris:\s*((?!\n).+)\s*\z//m;
  43. $price = $1;
  44. if ( $entry->property('attendee') ) {
  45. for ( @{ $entry->property('attendee') } ) {
  46. push @attendees, $_->parameters->{'CN'}
  47. || $_->value =~ s/^mailto://r;
  48. }
  49. }
  50. if ( $entry->property('attach') ) {
  51. for ( @{ $entry->property('attach') } ) {
  52. my $uri;
  53. try { $uri = URI->new( $_->value ) }
  54. catch ($e) {
  55. $log->errorf( 'failed to parse URI %s: %s', $uri, $e );
  56. next;
  57. }
  58. $uri->authority and $uri->host
  59. or next;
  60. push @attachments, $uri;
  61. }
  62. }
  63. if ( $log->is_trace ) {
  64. use DDP;
  65. p $entry;
  66. p $begin;
  67. p $end;
  68. }
  69. }
  70. method attendees { !!@attendees ? [@attendees] : undef }
  71. method attachments { !!@attachments ? [@attachments] : undef }
  72. 1;