diff options
Diffstat (limited to 'lib/Object/Groupware/Event.pm')
-rw-r--r-- | lib/Object/Groupware/Event.pm | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/lib/Object/Groupware/Event.pm b/lib/Object/Groupware/Event.pm new file mode 100644 index 0000000..52fa143 --- /dev/null +++ b/lib/Object/Groupware/Event.pm @@ -0,0 +1,84 @@ +use v5.36; +use Feature::Compat::Class 0.07; + +package Object::Groupware::Event 0.01; + +class Object::Groupware::Event; + +use utf8; + +use Log::Any qw( ); +use Feature::Compat::Try; + +field $log = Log::Any->get_logger; + +field $entry : param; + +field $begin : reader = $entry->start; +field $date_begin : reader = $begin->strftime('%A %e. %B'); +field $time_begin : reader = $begin->strftime('%k.%M'); +field $end : reader = $entry->end; +field $date_end : reader; +field $time_end : reader; +field $datespan : reader; +field $timespan : reader; +field $time_brief : reader; +field $summary : reader = $entry->summary; +field $description : reader = $entry->description; +field $location : reader = $entry->_simple_property('location'); +field $price : reader; +field @attendees; +field @attachments; + +ADJUST { + if ( defined $end ) { + $date_end = $end->strftime('%A %e. %B'); + $time_end = $end->strftime('%k.%M'); + } + $datespan + = ( defined $end and $date_end ne $date_begin ) + ? ucfirst("$date_begin - $date_end") + : ucfirst("$date_begin"); + $timespan + = ( defined $end and not $entry->all_day ) + ? ucfirst("$date_begin kl. $time_begin-$time_end") + : undef; + $time_brief + = $entry->all_day + ? $datespan + : ucfirst("$date_begin kl. $time_begin"); + $description =~ s/\n\n[Pp]ris:\s*((?!\n).+)\s*\z//m; + $price = $1; + + if ( $entry->property('attendee') ) { + for ( @{ $entry->property('attendee') } ) { + push @attendees, $_->parameters->{'CN'} + || $_->value =~ s/^mailto://r; + } + } + if ( $entry->property('attach') ) { + for ( @{ $entry->property('attach') } ) { + my $uri; + try { $uri = URI->new( $_->value ) } + catch ($e) { + $log->errorf( 'failed to parse URI %s: %s', $uri, $e ); + next; + } + $uri->authority and $uri->host + or next; + push @attachments, $uri; + } + } + + if ( $log->is_trace ) { + use DDP; + p $entry; + p $begin; + p $end; + } +} + +method attendees { !!@attendees ? [@attendees] : undef } +method attachments { !!@attachments ? [@attachments] : undef } + +1; |