| 1 | package EWS::Calendar::Item; | ||||||||||||||||||
| 2 | BEGIN { | ||||||||||||||||||
| 3 | 1 | ▶ | $EWS::Calendar::Item::VERSION = '1.143070'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | } | ||||||||||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 1 | ▶ | use DateTime::Format::ISO8601; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 1 | ▶ | use DateTime; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | 1 | ▶ | use HTML::Strip; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 1 | ▶ | use Encode; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | 1 | ▶ | use EWS::Calendar::Mailbox; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 1 | has Start => ( | |||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||
| 16 | isa => 'DateTime', | ||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||
| 18 | ); | ||||||||||||||||||
| 19 | |||||||||||||||||||
| 20 | 1 | has End => ( | |||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||
| 22 | isa => 'DateTime', | ||||||||||||||||||
| 23 | required => 1, | ||||||||||||||||||
| 24 | ); | ||||||||||||||||||
| 25 | |||||||||||||||||||
| 26 | 1 | has TimeSpan => ( | |||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||
| 28 | isa => 'Str', | ||||||||||||||||||
| 29 | lazy_build => 1, | ||||||||||||||||||
| 30 | ); | ||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | sub _build_TimeSpan { | ||||||||||||||||||
| 33 | 0 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
_build_TimeSpan: not called CC=3 SCAR=24.8
| |||||||||||||||||||
| 34 | # FIXME: plenty of edge cases we are not picking up on, yet | ||||||||||||||||||
| 35 | |||||||||||||||||||
| 36 | 0 | ▶ | if ($self->IsAllDayEvent) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 37 | 0 | ▶ | if ($self->Start->day == ($self->End->day - 1)) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 38 | 0 | return sprintf '%s %s %s', | |||||||||||||||||
| 39 | $self->Start->day, $self->Start->month_abbr, | ||||||||||||||||||
| 40 | $self->Start->year; | ||||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | else { | ||||||||||||||||||
| 43 | 0 | return sprintf '%s %s - %s, %s', | |||||||||||||||||
| 44 | $self->Start->month_abbr, $self->Start->day, | ||||||||||||||||||
| 45 | ($self->End->day - 1), $self->Start->year; | ||||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | else { | ||||||||||||||||||
| 49 | 0 | return sprintf '%s %s %s %s - %s', | |||||||||||||||||
| 50 | $self->Start->day, $self->Start->month_abbr, | ||||||||||||||||||
| 51 | $self->Start->year, $self->Start->strftime('%H:%M'), | ||||||||||||||||||
| 52 | $self->End->strftime('%H:%M'); | ||||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | } | ||||||||||||||||||
| 55 | |||||||||||||||||||
| 56 | 1 | has Subject => ( | |||||||||||||||||
| 57 | is => 'ro', | ||||||||||||||||||
| 58 | isa => 'Str', | ||||||||||||||||||
| 59 | required => 1, | ||||||||||||||||||
| 60 | ); | ||||||||||||||||||
| 61 | |||||||||||||||||||
| 62 | 1 | has Body => ( | |||||||||||||||||
| 63 | is => 'ro', | ||||||||||||||||||
| 64 | isa => 'Str', | ||||||||||||||||||
| 65 | required => 0, | ||||||||||||||||||
| 66 | default => '', | ||||||||||||||||||
| 67 | ); | ||||||||||||||||||
| 68 | |||||||||||||||||||
| 69 | 0 | ▶ | sub has_Body { return length ((shift)->Body) } | ||||||||||||||||
|
Subroutine
has_Body: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 70 | |||||||||||||||||||
| 71 | 1 | has Location => ( | |||||||||||||||||
| 72 | is => 'ro', | ||||||||||||||||||
| 73 | isa => 'Str', | ||||||||||||||||||
| 74 | required => 0, | ||||||||||||||||||
| 75 | default => '', | ||||||||||||||||||
| 76 | ); | ||||||||||||||||||
| 77 | |||||||||||||||||||
| 78 | 0 | ▶ | sub has_Location { return length ((shift)->Location) } | ||||||||||||||||
|
Subroutine
has_Location: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 1 | has CalendarItemType => ( | |||||||||||||||||
| 81 | is => 'ro', | ||||||||||||||||||
| 82 | isa => enum([qw/Single Occurrence Exception/]), | ||||||||||||||||||
| 83 | required => 1, | ||||||||||||||||||
| 84 | ); | ||||||||||||||||||
| 85 | |||||||||||||||||||
| 86 | 0 | ▶ | sub Type { (shift)->CalendarItemType } | ||||||||||||||||
|
Subroutine
Type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 87 | |||||||||||||||||||
| 88 | 0 | ▶ | sub IsRecurring { return ((shift)->Type ne 'Single') } | ||||||||||||||||
|
Subroutine
IsRecurring: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | 1 | has Sensitivity => ( | |||||||||||||||||
| 91 | is => 'ro', | ||||||||||||||||||
| 92 | isa => enum([qw/Normal Personal Private Confidential/]), | ||||||||||||||||||
| 93 | required => 1, | ||||||||||||||||||
| 94 | ); | ||||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | 1 | has DisplayTo => ( | |||||||||||||||||
| 97 | is => 'ro', | ||||||||||||||||||
| 98 | isa => 'ArrayRef[Str]', | ||||||||||||||||||
| 99 | required => 1, | ||||||||||||||||||
| 100 | ); | ||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | 0 | ▶ | sub has_DisplayTo { return scalar @{(shift)->DisplayTo} } | ||||||||||||||||
|
Subroutine
has_DisplayTo: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 103 | |||||||||||||||||||
| 104 | 1 | has Organizer => ( | |||||||||||||||||
| 105 | is => 'ro', | ||||||||||||||||||
| 106 | isa => 'EWS::Calendar::Mailbox', | ||||||||||||||||||
| 107 | required => 1, | ||||||||||||||||||
| 108 | ); | ||||||||||||||||||
| 109 | |||||||||||||||||||
| 110 | 1 | has IsCancelled => ( | |||||||||||||||||
| 111 | is => 'ro', | ||||||||||||||||||
| 112 | isa => 'Int', # bool | ||||||||||||||||||
| 113 | lazy_build => 1, | ||||||||||||||||||
| 114 | ); | ||||||||||||||||||
| 115 | |||||||||||||||||||
| 116 | sub _build_IsCancelled { | ||||||||||||||||||
| 117 | 0 | ▶ | my $self = shift; | ||||||||||||||||
|
Subroutine
_build_IsCancelled: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 118 | 0 | return ($self->AppointmentState & 0x0004); | |||||||||||||||||
| 119 | } | ||||||||||||||||||
| 120 | |||||||||||||||||||
| 121 | 1 | has AppointmentState => ( | |||||||||||||||||
| 122 | is => 'ro', | ||||||||||||||||||
| 123 | isa => 'Str', # bool - Was 'Int' but failed type constraint on 2012-06-20 | ||||||||||||||||||
| 124 | required => 1, | ||||||||||||||||||
| 125 | ); | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | 1 | has LegacyFreeBusyStatus => ( | |||||||||||||||||
| 128 | is => 'ro', | ||||||||||||||||||
| 129 | isa => 'Str', # Was enum([qw/Free Tentative Busy OOF NoData/]), | ||||||||||||||||||
| 130 | required => 0, | ||||||||||||||||||
| 131 | default => 'NoData', | ||||||||||||||||||
| 132 | ); | ||||||||||||||||||
| 133 | |||||||||||||||||||
| 134 | 0 | ▶ | sub Status { (shift)->LegacyFreeBusyStatus } | ||||||||||||||||
|
Subroutine
Status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||
| 135 | |||||||||||||||||||
| 136 | 1 | has IsDraft => ( | |||||||||||||||||
| 137 | is => 'ro', | ||||||||||||||||||
| 138 | isa => 'Int', # bool | ||||||||||||||||||
| 139 | required => 1, | ||||||||||||||||||
| 140 | ); | ||||||||||||||||||
| 141 | |||||||||||||||||||
| 142 | 1 | has IsAllDayEvent => ( | |||||||||||||||||
| 143 | is => 'ro', | ||||||||||||||||||
| 144 | isa => 'Int', # bool | ||||||||||||||||||
| 145 | required => 0, | ||||||||||||||||||
| 146 | default => 0, | ||||||||||||||||||
| 147 | ); | ||||||||||||||||||
| 148 | |||||||||||||||||||
| 149 | 1 | has Sensitivity => ( | |||||||||||||||||
| 150 | is => 'ro', | ||||||||||||||||||
| 151 | isa => enum([qw/Normal Personal Private Confidential/]), | ||||||||||||||||||
| 152 | required => 1, | ||||||||||||||||||
| 153 | ); | ||||||||||||||||||
| 154 | |||||||||||||||||||
| 155 | 1 | has RequiredAttendees => ( | |||||||||||||||||
| 156 | is => 'ro', | ||||||||||||||||||
| 157 | isa => 'ArrayRef[EWS::Calendar::Mailbox]', | ||||||||||||||||||
| 158 | required => 0, | ||||||||||||||||||
| 159 | ); | ||||||||||||||||||
| 160 | |||||||||||||||||||
| 161 | 1 | has Duration => ( | |||||||||||||||||
| 162 | is => 'ro', | ||||||||||||||||||
| 163 | isa => 'Str', | ||||||||||||||||||
| 164 | required => 1, | ||||||||||||||||||
| 165 | ); | ||||||||||||||||||
| 166 | |||||||||||||||||||
| 167 | 1 | has OptionalAttendees => ( | |||||||||||||||||
| 168 | is => 'ro', | ||||||||||||||||||
| 169 | isa => 'ArrayRef[EWS::Calendar::Mailbox]', | ||||||||||||||||||
| 170 | required => 0, | ||||||||||||||||||
| 171 | ); | ||||||||||||||||||
| 172 | |||||||||||||||||||
| 173 | 1 | has UID => ( | |||||||||||||||||
| 174 | is => 'ro', | ||||||||||||||||||
| 175 | isa => 'Str', | ||||||||||||||||||
| 176 | required => 0, | ||||||||||||||||||
| 177 | default => '', | ||||||||||||||||||
| 178 | ); | ||||||||||||||||||
| 179 | |||||||||||||||||||
| 180 | sub BUILDARGS { | ||||||||||||||||||
| 181 | 0 | ▶ | my ($class, @rest) = @_; | ||||||||||||||||
|
Subroutine
BUILDARGS: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||
| 182 | 0 | ▶ | my $params = (scalar @rest == 1 ? $rest[0] : {@rest}); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 183 | |||||||||||||||||||
| 184 | # could coerce but this is always required, so do it here instead | ||||||||||||||||||
| 185 | 0 | $params->{'Start'} = DateTime::Format::ISO8601->parse_datetime($params->{'Start'}); | |||||||||||||||||
| 186 | 0 | $params->{'End'} = DateTime::Format::ISO8601->parse_datetime($params->{'End'}); | |||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | # fish data out of deep structure | ||||||||||||||||||
| 189 | 0 | $params->{'Organizer'} = EWS::Calendar::Mailbox->new($params->{'Organizer'}->{'Mailbox'}); | |||||||||||||||||
| 190 | 0 | $params->{'OptionalAttendees'} = [ map { EWS::Calendar::Mailbox->new($_->{'Mailbox'}) } | |||||||||||||||||
| 191 | 0 | @{$params->{'OptionalAttendees'}->{Attendee}} ]; | |||||||||||||||||
| 192 | 0 | $params->{'RequiredAttendees'} = [ map { EWS::Calendar::Mailbox->new($_->{'Mailbox'}) } | |||||||||||||||||
| 193 | 0 | @{$params->{'RequiredAttendees'}->{Attendee}} ]; | |||||||||||||||||
| 194 | 0 | $params->{'Body'} = $params->{'Body'}->{'_'}; | |||||||||||||||||
| 195 | |||||||||||||||||||
| 196 | # rework semicolon separated list into array, and also remove Organizer | ||||||||||||||||||
| 197 | 0 | $params->{'DisplayTo'} = [ grep {$_ ne $params->{'Organizer'}->{'Name'}} | |||||||||||||||||
| 198 | 0 | split m/; /, $params->{'DisplayTo'} ]; | |||||||||||||||||
| 199 | |||||||||||||||||||
| 200 | # set Perl's encoding flag on all data coming from Exchange | ||||||||||||||||||
| 201 | # also strip HTML tags from incoming data | ||||||||||||||||||
| 202 | 0 | my $hs = HTML::Strip->new(emit_spaces => 0); | |||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | 0 | foreach my $key (keys %$params) { | |||||||||||||||||
| 205 | 0 | ▶ | if ( $key =~ /RequiredAttendees|OptionalAttendees|IsDraft|IsAllDayEvent/ ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 206 | 0 | next; | |||||||||||||||||
| 207 | } | ||||||||||||||||||
| 208 | elsif (ref $params->{$key} eq 'ARRAY') { | ||||||||||||||||||
| 209 | $params->{$key} = [ | ||||||||||||||||||
| 210 | 0 | map {$hs->parse($_)} | |||||||||||||||||
| 211 | 0 | map {Encode::encode('utf8', $_)} | |||||||||||||||||
| 212 | 0 | @{ $params->{$key} } | |||||||||||||||||
| 213 | ]; | ||||||||||||||||||
| 214 | } | ||||||||||||||||||
| 215 | elsif (ref $params->{$key}) { | ||||||||||||||||||
| 216 | 0 | next; | |||||||||||||||||
| 217 | } | ||||||||||||||||||
| 218 | else { | ||||||||||||||||||
| 219 | 0 | $params->{$key} = $hs->parse(Encode::encode('utf8', $params->{$key})); | |||||||||||||||||
| 220 | } | ||||||||||||||||||
| 221 | } | ||||||||||||||||||
| 222 | |||||||||||||||||||
| 223 | # the Body is usually a mess if created by Outlook | ||||||||||||||||||
| 224 | 0 | $params->{'Body'} =~ s/^\s+//; | |||||||||||||||||
| 225 | 0 | $params->{'Body'} =~ s/\s+$//; | |||||||||||||||||
| 226 | 0 | $params->{'Body'} =~ s/\n{3,}/\n\n/g; | |||||||||||||||||
| 227 | 0 | $params->{'Body'} =~ s/ {2,}/ /g; | |||||||||||||||||
| 228 | |||||||||||||||||||
| 229 | 0 | return $params; | |||||||||||||||||
| 230 | } | ||||||||||||||||||
| 231 | |||||||||||||||||||
| 232 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||
| 233 | 1 | ▶ | no Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 234 | 1 | 1; | |||||||||||||||||