use v5.36; use Feature::Compat::Class 0.07; package Object::Groupware::Event 0.01; class Object::Groupware::Event : isa(Object::Groupware); use utf8; use Log::Any qw( ); use Feature::Compat::Try; use DateTime::Locale; field $log = Log::Any->get_logger; field $entry : param; field $dt_locale; field $begin : reader = $entry->start; field $end : reader = $entry->end; 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 ( $self->dt_locale ) { $dt_locale = $self->dt_locale; $begin->set_locale($dt_locale); $end->set_locale($dt_locale) if defined $end; } else { # we need the object regardless, to fetch CLDR patterns $dt_locale = DateTime::Locale->load('en_US'); } $begin->set_locale( $self->dt_locale ); for ( $self->dt_time_zone || () ) { $begin->set_time_zone($_); $end->set_time_zone($_) if defined $end; } $datespan = ( defined $end and $end->clone->truncate( to => 'day' ) ne $begin->clone->truncate( to => 'day' ) ) ? ucfirst( sprintf '%s - %s', $begin->format_cldr( $dt_locale->date_format_medium() ), $end->format_cldr( $dt_locale->date_format_medium() ) ) : ucfirst( $begin->format_cldr( $dt_locale->date_format_medium() ) ); $timespan = ( defined $end and not $entry->all_day ) ? ucfirst( sprintf '%s-%s', $begin->format_cldr( $dt_locale->datetime_format_medium() ), $end->format_cldr( $dt_locale->time_format_medium() ) ) : undef; $time_brief = $entry->all_day ? $datespan : ucfirst( $begin->format_cldr( $dt_locale->datetime_format_medium() ) ); $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;