JSCalendar.pm

filter: Statementstmt 95.3% 1638 / 1718 Branchbran 82.5% 946 / 1146 Conditioncond 71.5% 514 / 718 MC/DCmcdc 48.5% 201 / 414 Subroutinesub 98.2% 111 / 113 Podpod 83.3% 10 / 12 totaltotal 82.9% 3420 / 4121 CC 926 SCAR 49.0
CC
926
Cov
86%
_vEventToEvent
401.9
_argsToVEvents
166.9
_expandRule
104.2
CRAP 134.3
« JSCalendar/TimeZones.pm ↑ Summary
1 #/usr/bin/perl -cw
2 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 18 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package Text::JSCalendar;
5  
6 18 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use Data::ICal;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use Data::ICal::Entry::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Data::ICal::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 18 ▶use Data::ICal::Entry::Alarm::Email;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 18 ▶use Data::ICal::Entry::Alarm::Display;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 18 ▶use DateTime::Format::ICal;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 18 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 18 ▶use JSON::XS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 18 ▶use Text::JSCalendar::TimeZones;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 18 ▶use Text::VCardFast qw(vcard2hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶use MIME::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 18 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 18 ▶use Text::JSCalendar::TimeZones;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # monkey patch like a bandit
26 18 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
27 18 my @alarm_properties = Data::ICal::Entry::Alarm::optional_unique_properties();
28 18 foreach my $want (qw(uid acknowledged)) {
29 36 ▶ push @alarm_properties, $want unless grep { $_ eq $want } @alarm_properties;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $want;} @alarm_properties 36 0 36
30 }
31 18 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 18 ▶ *Data::ICal::Entry::Alarm::optional_unique_properties = sub { @alarm_properties };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 }
34  
35 18 our $UTC = DateTime::TimeZone::UTC->new();
36 18 our $FLOATING = DateTime::TimeZone::Floating->new();
37 18 our $LOCALE = DateTime::Locale->load('en_US');
38  
39 # MIME::Types->new is slow; made once, when an ATTACH first needs it
40 18 my $MimeTypes;
41  
42 # The vendor-specific property (jscalendarbis-22 1.8.1) that marks a
43 # master the reader made up; see "Synthetic masters" in the POD.
44 18 ▶use constant SYNTHETIC_MASTER => 'jscalendar.fastmail.com:syntheticMaster';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 my (
47 18 %ValidDay,
48 %ValidFrequency,
49 %EventKeys,
50 %ColorNames,
51 %RecurrenceProperties,
52 %UTCLinks,
53 %MustBeTopLevel,
54 %OrganizerOnly,
55 );
56  
57 18 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 18 %ValidDay = map { $_ => 1 } qw(su mo tu we th fr sa);
59 18 %ValidFrequency = map { $_ => 1 } qw(yearly monthly weekly daily hourly minutely secondly);
60  
61 # Property name => [container, type, required, default], per object
62 # type (the key "" is the Event or Task itself). container is 0 for a
63 # single value, 1 for an array, 2 for an Id- or String-keyed map; type
64 # "object" recurses into the table of the same name and "patch" into
65 # a PatchObject. Defaults are jscalendarbis-22 (or RFC 8984 for the
66 # properties -22 reserved); only NormaliseEvent reads this table.
67 18 %EventKeys = (
68 '' => {
69 uid => [0, 'string', 1, undef],
70 relatedTo => [2, 'object', 0, undef],
71 keywords => [0, 'keywords', 0, undef],
72 categories => [0, 'keywords', 0, undef],
73 prodId => [0, 'string', 0, undef],
74 created => [0, 'utcdate', 0, undef],
75 updated => [0, 'utcdate', 1, undef],
76 sequence => [0, 'number', 0, 0],
77 method => [0, 'string', 0, undef],
78 title => [0, 'string', 0, ''],
79 description => [0, 'string', 0, ''],
80 descriptionContentType => [0, 'string', 0, "text/plain"], # jscalendarbis-22 3.2.3
81 links => [2, 'object', 0, undef],
82 locale => [0, 'string', 0, undef],
83 locations => [2, 'object', 0, undef],
84 virtualLocations => [2, 'object', 0, undef],
85 color => [0, 'string', 0, undef],
86 showWithoutTime => [0, 'bool', 0, $JSON::false],
87 start => [0, 'localdate', 1, undef],
88 timeZone => [0, 'timezone', 0, undef],
89 duration => [0, 'duration', 0, "PT0S"], # jscalendarbis-22 4.1.2
90 recurrenceRule => [0, 'object', 0, undef],
91 recurrenceOverrides => [2, 'patch', 0, undef],
92 recurrenceId => [0, 'localdate', 0, undef],
93 recurrenceIdTimeZone => [0, 'timezone', 0, undef],
94 status => [0, 'string', 0, "confirmed"], # jscalendarbis-22 4.1.4
95 freeBusyStatus => [0, 'string', 0, 'busy'],
96 privacy => [0, 'string', 0, 'public'],
97 priority => [0, 'number', 0, 0],
98 organizerCalendarAddress => [0, 'string', 0, undef],
99 sentBy => [0, 'string', 0, undef],
100 endTimeZone => [0, 'timezone', 0, undef],
101 participants => [2, 'object', 0, undef],
102 alerts => [2, 'object', 0, undef],
103 version => [0, 'string', 0, undef],
104 # Task-specific properties
105 due => [0, 'localdate', 0, undef],
106 estimatedDuration => [0, 'duration', 0, undef],
107 percentComplete => [0, 'number', 0, undef],
108 progress => [0, 'string', 0, undef],
109 },
110 links => {
111 href => [0, 'string', 1, undef],
112 contentType => [0, 'string', 0, undef],
113 size => [0, 'number', 0, undef],
114 rel => [0, 'string', 0, 'enclosure'], # jscalendarbis-22 1.5.11
115 title => [0, 'string', 0, undef],
116 display => [2, 'bool', 0, undef],
117 },
118 locations => {
119 name => [0, 'string', 0, undef],
120 coordinates => [0, 'string', 0, undef],
121 locationTypes => [0, 'keywords', 0, undef],
122 links => [2, 'object', 0, undef],
123 },
124 virtualLocations => {
125 name => [0, 'string', 0, ''],
126 uri => [0, 'string', 1, undef],
127 features => [0, 'keywords', 0, undef],
128 },
129 recurrenceRule => {
130 frequency => [0, 'string', 1, undef],
131 interval => [0, 'number', 0, 1], # jscalendarbis-22 3.3.3
132 rscale => [0, 'string', 0, 'gregorian'],
133 skip => [0, 'string', 0, 'omit'],
134 firstDayOfWeek => [0, 'string', 0, 'mo'],
135 byDay => [1, 'object', 0, undef],
136 byMonthDay => [1, 'number', 0, undef],
137 byMonth => [1, 'string', 0, undef],
138 byYearDay => [1, 'number', 0, undef],
139 byWeekNo => [1, 'number', 0, undef],
140 byHour => [1, 'number', 0, undef],
141 byMinute => [1, 'number', 0, undef],
142 bySecond => [1, 'number', 0, undef],
143 bySetPosition => [1, 'number', 0, undef],
144 count => [0, 'number', 0, undef],
145 until => [0, 'localdate', 0, undef],
146 },
147 relatedTo => {
148 relation => [2, 'bool', 0, undef],
149 },
150 byDay => {
151 day => [0, 'string', 1, undef],
152 nthOfPeriod => [0, 'number', 0, undef],
153 },
154 participants => {
155 name => [0, 'string', 1, undef],
156 email => [0, 'string', 1, undef],
157 calendarAddress => [0, 'string', 0, undef],
158 kind => [0, 'string', 0, undef], # no default (jscalendarbis-22 3.4.6)
159 roles => [2, 'bool', 1, undef],
160 locationId => [0, 'string', 0, undef],
161 participationStatus => [0, 'string', 0, 'needs-action'],
162 expectReply => [0, 'bool', 0, $JSON::false],
163 scheduleAgent => [0, 'string', 0, "server"], # RFC 8984 4.4.6
164 scheduleSequence => [0, 'number', 0, 0],
165 scheduleUpdated => [0, 'utcdate', 0, undef],
166 scheduleStatus => [1, 'string', 0, undef],
167 participationComment => [0, 'string', 0, undef],
168 invitedBy => [0, 'string', 0, undef],
169 memberOf => [2, 'bool', 0, undef],
170 sentBy => [0, 'string', 0, undef],
171 progress => [0, 'string', 0, undef],
172 progressUpdated => [0, 'utcdate', 0, undef],
173 delegatedFrom => [0, 'keywords', 0, undef],
174 delegatedTo => [0, 'keywords', 0, undef],
175 description => [0, 'string', 0, undef],
176 descriptionContentType => [0, 'string', 0, undef],
177 links => [2, 'object', 0, undef],
178 },
179 alerts => {
180 trigger => [0, 'object', 1, undef],
181 acknowledged => [0, 'string', 0, undef],
182 action => [0, 'string', 0, 'display'],
183 },
184 # the Alert trigger: an OffsetTrigger when @type is unset or
185 # "OffsetTrigger" (its defaultType, jscalendarbis-22 3.5.1); any other
186 # @type is kept as it is
187 trigger => {
188 offset => [0, 'string', 1, undef],
189 relativeTo => [0, 'string', 0, 'start'],
190 },
191 );
192  
193 18 %RecurrenceProperties = (
194 bymonthday => {
195 name => 'byMonthDay',
196 max => 31,
197 signed => 1,
198 },
199 byyearday => {
200 name => 'byYearDay',
201 max => 366,
202 signed => 1,
203 },
204 byweekno => {
205 name => 'byWeekNo',
206 max => 53,
207 signed => 1,
208 },
209 byhour => {
210 name => 'byHour',
211 max => 23,
212 },
213 byminute => {
214 name => 'byMinute',
215 max => 59,
216 },
217 bysecond => {
218 name => 'bySecond',
219 max => 60,
220 },
221 bysetpos => {
222 name => 'bySetPosition',
223 max => 366,
224 signed => 1,
225 },
226 );
227  
228 18 %MustBeTopLevel = map { $_ => 1 } SYNTHETIC_MASTER, qw{
229 @type
230 uid
231 prodId
232 showWithoutTime
233 recurrenceRule
234 recurrenceOverrides
235 organizerCalendarAddress
236 method
237 privacy
238 sentBy
239 recurrenceId
240 recurrenceIdTimeZone
241 };
242  
243 # Participant properties that convert to ORGANIZER parameters
244 18 %OrganizerOnly = map { $_ => 1 } qw{
245 @type
246 calendarAddress
247 email
248 name
249 roles
250 sentBy
251 };
252  
253 # Color names defined in CSS Color Module Level 3
254 # http://www.w3.org/TR/css3-color/
255  
256 %ColorNames
257 18 = map { $_ => 1 }
258 qw{
259 aliceblue
260 antiquewhite
261 aqua
262 aquamarine
263 azure
264 beige
265 bisque
266 black
267 blanchedalmond
268 blue
269 blueviolet
270 brown
271 burlywood
272 cadetblue
273 chartreuse
274 chocolate
275 coral
276 cornflowerblue
277 cornsilk
278 crimson
279 cyan
280 darkblue
281 darkcyan
282 darkgoldenrod
283 darkgray
284 darkgreen
285 darkgrey
286 darkkhaki
287 darkmagenta
288 darkolivegreen
289 darkorange
290 darkorchid
291 darkred
292 darksalmon
293 darkseagreen
294 darkslateblue
295 darkslategray
296 darkslategrey
297 darkturquoise
298 darkviolet
299 deeppink
300 deepskyblue
301 dimgray
302 dimgrey
303 dodgerblue
304 firebrick
305 floralwhite
306 forestgreen
307 fuchsia
308 gainsboro
309 ghostwhite
310 gold
311 goldenrod
312 gray
313 green
314 greenyellow
315 grey
316 honeydew
317 hotpink
318 indianred
319 indigo
320 ivory
321 khaki
322 lavender
323 lavenderblush
324 lawngreen
325 lemonchiffon
326 lightblue
327 lightcoral
328 lightcyan
329 lightgoldenrodyellow
330 lightgray
331 lightgreen
332 lightgrey
333 lightpink
334 lightsalmon
335 lightseagreen
336 lightskyblue
337 lightslategray
338 lightslategrey
339 lightsteelblue
340 lightyellow
341 lime
342 limegreen
343 linen
344 magenta
345 maroon
346 mediumaquamarine
347 mediumblue
348 mediumorchid
349 mediumpurple
350 mediumseagreen
351 mediumslateblue
352 mediumspringgreen
353 mediumturquoise
354 mediumvioletred
355 midnightblue
356 mintcream
357 mistyrose
358 moccasin
359 navajowhite
360 navy
361 oldlace
362 olive
363 olivedrab
364 orange
365 orangered
366 orchid
367 palegoldenrod
368 palegreen
369 paleturquoise
370 palevioletred
371 papayawhip
372 peachpuff
373 peru
374 pink
375 plum
376 powderblue
377 purple
378 red
379 rosybrown
380 royalblue
381 saddlebrown
382 salmon
383 sandybrown
384 seagreen
385 seashell
386 sienna
387 silver
388 skyblue
389 slateblue
390 slategray
391 slategrey
392 snow
393 springgreen
394 steelblue
395 tan
396 teal
397 thistle
398 tomato
399 turquoise
400 violet
401 wheat
402 white
403 whitesmoke
404 yellow
405 yellowgreen
406 };
407  
408 18 %UTCLinks = (
409 'Etc/GMT-0' => 1,
410 'Etc/GMT+0' => 1,
411 'Etc/GMT0' => 1,
412 'Etc/GMT' => 1,
413 'Etc/Greenwich' => 1,
414 'Etc/UCT' => 1,
415 'Etc/Universal' => 1,
416 'Etc/UTC' => 1,
417 'Etc/Zulu' => 1,
418 'GMT' => 1,
419 'UCT' => 1,
420 'UTC' => 1,
421 );
422 }
423  
424  
425 =head1 NAME
426  
427 Text::JSCalendar
428  
429 =head1 VERSION
430  
431 Version 0.10
432  
433 =cut
434  
435 18 our $VERSION = '0.10';
436  
437 =head1 SYNOPSIS
438  
439 This module implements a perl mapping between iCalendar:
440  
441 https://tools.ietf.org/html/rfc5545
442  
443 and JSCalendar:
444  
445 https://datatracker.ietf.org/doc/draft-ietf-calext-jscalendar/
446  
447 =head1 SUBROUTINES/METHODS
448  
449 =cut
450  
451 15 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod undocumented
452 15 my $class = shift;
453 15 ▶ return bless {@_}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0150
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
454 }
455  
456 =head2 Synthetic masters
457  
458 An iCalendar object may hold only some instances of a recurring event
459 (RECURRENCE-ID components without their master, as a CalDAV server
460 gives an attendee invited to one occurrence: jscalendar-icalendar-29
461 calls them stand-alone recurrence instances). C<vcalendarToEvents>
462 returns a single object per UID, so it makes up a master for them: its
463 C<start>, C<timeZone>, C<updated> and the properties an override may not
464 change come from the first instance, and every instance is one of its
465 C<recurrenceOverrides> (even one that patches nothing).
466  
467 Such a master is marked with the vendor-specific property
468  
469 "jscalendar.fastmail.com:syntheticMaster": true
470  
471 (jscalendarbis-22 1.8.1, so it cannot collide with a JSCalendar
472 property, and JSCalendar implementations must preserve it). The name is
473 the constant C<Text::JSCalendar::SYNTHETIC_MASTER>. It is in the object
474 rather than beside it so that it survives being stored and read back
475 before the object is written again.
476  
477 C<eventsToVCalendar> writes only the instances of a marked master, each
478 as a RECURRENCE-ID component (an excluded one is not written), and never
479 a component for the master itself. Every other object is written whole.
480 To turn a synthetic master into a real one, delete the property.
481 C<occurrences> of a synthetic master are its override keys, and
482 C<instance> gives the instance with the property removed.
483  
484 =head2 Text::JSCalendar->isSyntheticMaster($Event)
485  
486 True if C<$Event> is a master made up by the reader (see above). May
487 also be called on an object or as a function.
488  
489 =cut
490  
491 360 ▶sub isSyntheticMaster {
Subroutine isSyntheticMaster: called CC=3 SCAR=11.1
Pod documented
492 360 my $Event = pop;
493 360 ▶ return 0 unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 360 360
494 360 ▶ return $Event->{SYNTHETIC_MASTER()} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Event->{'jscalendar.fastmail.com:syntheticMaster'} ? : 23 337 360
495 }
496  
497 =head2 $self->errors()
498  
499 What the last call to C<vcalendarToEvents> or C<eventsToVCalendar> (or
500 C<_argsToVCalendar>) had to drop. Neither dies because one component
501 is bad: an iCalendar VEVENT or VTODO, VALARM or RRULE that cannot be
502 converted is left out of the result, and so is a JSCalendar object or
503 alert that cannot be written. The rest of the calendar converts as
504 usual.
505  
506 Returns a list of hashes, empty when nothing was dropped:
507  
508 {
509 uid => 'abc@example.com', # the object's UID (undef if it had none)
510 component => 'RRULE', # what was dropped: VEVENT, VTODO,
511 # VALARM, RRULE (reading), or
512 # Event, Task, Alert (writing)
513 id => 'alarm-1', # the alarm or alert id, if known
514 message => 'Invalid recurrence FREQ (fortnightly)',
515 }
516  
517 The list is reset at the start of each of those calls, and so is
518 C<warnings>.
519  
520 =cut
521  
522 474 ▶sub errors {
Subroutine errors: called CC=2 SCAR=7.1
Pod documented
523 474 my $Self = shift;
524 474 ▶ return @{$Self->{_errors} || []};
Condition50%1/2
$Self->{'_errors'} || []
l!l
4740
MC/DC0%0/1
$Self->{'_errors'} || []
$Self->{'_errors'}
Truth table50%1/2
A
A= $Self->{'_errors'}
Aresult
11
00
525 }
526  
527 =head2 $self->warnings()
528  
529 What the last call to C<vcalendarToEvents> or C<eventsToVCalendar> (or
530 C<_argsToVCalendar>) found odd but converted anyway: an iCalendar
531 component with both DTEND and DURATION, a second component of one UID
532 without RECURRENCE-ID, a property Data::ICal says is missing. The same
533 shape as C<errors>, and reset with it. The module never writes these to
534 STDERR.
535  
536 =cut
537  
538 2 ▶sub warnings {
Subroutine warnings: called CC=2 SCAR=7.1
Pod documented
539 2 my $Self = shift;
540 2 ▶ return @{$Self->{_warnings} || []};
Condition50%1/2
$Self->{'_warnings'} || []
l!l
20
MC/DC0%0/1
$Self->{'_warnings'} || []
$Self->{'_warnings'}
Truth table50%1/2
A
A= $Self->{'_warnings'}
Aresult
11
00
541 }
542  
543 5 ▶sub _warning {
Subroutine _warning: called CC=1 SCAR=0.0
544 5 my ($Self, $uid, $component, $msg) = @_;
545 5 push @{$Self->{_warnings}}, {
546 uid => $uid,
547 component => $component,
548 message => $msg,
549 };
550 }
551  
552 625 ▶sub _resetDiagnostics {
Subroutine _resetDiagnostics: called CC=1 SCAR=0.0
553 625 my $Self = shift;
554 625 $Self->{_errors} = [];
555 625 $Self->{_warnings} = [];
556 }
557  
558 # Run $code with Data::ICal's carps caught: it warns about every property
559 # it does not know (COLOR, CONFERENCE, ...: most of what this module
560 # writes) and about missing mandatory ones. The first are expected; the
561 # second become warnings(). Any other warning goes on to the caller's
562 # handler. (This used to be a $SIG{__WARN__} replaced for the whole
563 # process when the module was loaded.)
564 465 ▶sub _withICalWarnings {
Subroutine _withICalWarnings: called CC=1 SCAR=0.4
565 465 my ($Self, $code) = @_;
566 465 my $outer = $SIG{__WARN__};
567 42 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=4 SCAR=16.6
568 42 my $msg = $_[0];
569 42 ▶ return if $msg =~ /^Unknown property for Data::ICal::Entry::/;
Branch: 1 branch
BranchTrueFalseTotal
if $msg =~ /^Unknown property for Data::ICal::Entry::/ 39 3 42
570 3 ▶ if ($msg =~ /^Mandatory property for (Data::ICal::\S+) missing: (\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /^Mandatory property for (Data::ICal::\S+) missing: (\S+)/) 3 0 3
571 3 $Self->_warning(undef, $1, "missing mandatory property $2");
572 3 return;
573 }
574 0 ▶ if (ref $outer eq 'CODE') { $outer->(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $outer eq 'CODE') { } 0 0 0
575 0 else { warn @_ }
576 465 };
577 465 return $code->();
578 }
579  
580 # Report a dropped component. $msg is a die message: only its first
581 # line is kept, without Carp's location.
582 18 ▶sub _error {
Subroutine _error: called CC=4 SCAR=14.0
583 18 my ($Self, $uid, $component, $msg, $id) = @_;
584 18 ▶ $msg = defined $msg ? "$msg" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $msg ? : 18 0 18
585 18 $msg =~ s/\n.*//s;
586 18 $msg =~ s/ at \S+ line \d+\.?$//;
587 18 ▶ $msg = 'unknown error' unless length $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless length $msg 0 18 18
588 18 ▶ push @{$Self->{_errors}}, {
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 2 16 18
589 uid => $uid,
590 component => $component,
591 defined $id ? (id => $id) : (),
592 message => $msg,
593 };
594 }
595  
596 =head2 $self->tz($name)
597  
598 Returns a DateTime::TimeZone object for the given name, but caches
599 the result for speed.
600  
601 =cut
602  
603 2322 ▶sub tz {
Subroutine tz: called CC=4 SCAR=13.9
Pod documented
604 2322 my $Self = shift;
605 2322 my $tzName = shift;
606 2322 ▶ return $FLOATING unless defined $tzName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tzName 13 2309 2322
607 2309 ▶ return $UTC if $UTCLinks{$tzName};
Branch: 1 branch
BranchTrueFalseTotal
if $UTCLinks{$tzName} 1539 770 2309
608 770 ▶ unless (exists $Self->{_tz}{$tzName}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Self->{"_tz"}{$tzName}) 15 755 770
609 15 $Self->{_tz}{$tzName} = DateTime::TimeZone->new(name => $tzName);
610 }
611 770 return $Self->{_tz}{$tzName};
612 }
613  
614 0 ▶sub color {
Subroutine color: not called CC=1 SCAR=6.9
Pod undocumented
615 0 my $Self = shift;
616 0 my $color = shift;
617 0 return _fixColor($color);
618 }
619  
620 23 ▶sub _fixColor {
Subroutine _fixColor: called CC=7 SCAR=19.6
621 23 ▶ my $color = lc(shift || '');
Condition50%1/2
shift() || ''
l!l
230
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
622  
623 23 ▶ return $color if $ColorNames{$color};
Branch: 1 branch
BranchTrueFalseTotal
if $ColorNames{$color} 13 10 23
624 10 ▶ confess("unparseable color: $color") unless $color =~ m/^\s*(\#[a-f0-9]{3,8})\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $color =~ /^\s*(\#[a-f0-9]{3,8})\s*$/ 2 8 10
625 8 $color = $1;
626 8 ▶ return uc($color) if length($color) == 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $color == 7 6 2 8
627  
628 # Optional digit is for transparency (RGBA)
629 2 ▶ if ( $color =~ m/^#(.)(.)(.).?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color =~ /^#(.)(.)(.).?$/) 1 1 2
630 1 return uc "#$1$1$2$2$3$3";
631 }
632  
633 # Last two digits are for transparency (RGBA)
634 1 ▶ if ( length($color) == 9 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $color == 9) 0 1 1
635 0 return uc(substr($color,0,7));
636 }
637  
638 1 confess("invalid color: $color"); # e.g. five or seven hex digits
639 }
640  
641 43 ▶sub _BYDAY2byDay {
Subroutine _BYDAY2byDay: called CC=7 SCAR=22.0
642 43 my ($BYDAY) = @_;
643  
644 43 my ($Count, $Day) = $BYDAY =~ /^([-+]?\d+)?(\w\w)$/;
645  
646 43 ▶ unless ($Day) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Day) 0 43 43
647 0 confess 'Recurrence BYDAY-weekday not specified';
648 }
649  
650 43 ▶ unless ($ValidDay{lc $Day}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{lc $Day}) 0 43 43
651 0 confess 'Invalid recurrence BYDAY-weekday';
652 }
653  
654 43 ▶ if ($Count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Count) 26 17 43
655 26 ▶ unless (($Count >= -53) and ($Count <= 53)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Count >= -53 and $Count <= 53) 0 26 26
Condition33%1/3
$Count >= -53 and $Count <= 53
!ll&&!rl&&r
0026
MC/DC0%0/2
$Count >= -53 and $Count <= 53
$Count >= -53 $Count <= 53
Truth table33%1/3
A and B
A= $Count >= -53B= $Count <= 53
ABresult
0X0
100
111
656 0 confess 'Recurrence BYDAY-ordwk is out of range';
657 }
658 }
659  
660 return {
661 43 ▶ '@type' => 'NDay',
Branch: 1 branch
BranchTrueFalseTotal
$Count ? : 26 17 43
662 day => lc $Day,
663 $Count ? (nthOfPeriod => int($Count)) : (),
664 };
665 }
666  
667 30 ▶sub _byDay2BYDAY {
Subroutine _byDay2BYDAY: called CC=6 SCAR=20.5
668 30 my ($byDay) = @_;
669  
670 30 ▶ unless (defined $byDay) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $byDay) 0 30 30
671 0 confess 'Invalid recurrence byDay';
672 }
673  
674 30 ▶ unless (ref $byDay eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $byDay eq "HASH") 0 30 30
675 0 confess 'Recurrence byDay is not an object';
676 }
677  
678 30 my $Day = $byDay->{day};
679 30 ▶ unless ($Day and $ValidDay{lc $Day}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Day and $ValidDay{lc $Day}) 0 30 30
Condition33%1/3
$Day and $ValidDay{lc $Day}
!ll&&!rl&&r
0030
MC/DC0%0/2
$Day and $ValidDay{lc $Day}
$Day $ValidDay{lc $Day}
Truth table33%1/3
A and B
A= $DayB= $ValidDay{lc $Day}
ABresult
0X0
100
111
680 0 confess 'Recurrence byDay is not a known day';
681 }
682  
683 30 my $Prefix = '';
684 30 ▶ $Prefix = int($byDay->{nthOfPeriod}) if $byDay->{nthOfPeriod};
Branch: 1 branch
BranchTrueFalseTotal
if $byDay->{"nthOfPeriod"} 18 12 30
685  
686 30 return $Prefix . uc($Day);
687 }
688  
689 1408 ▶sub _makeDateObj {
Subroutine _makeDateObj: called CC=4 SCAR=13.9
690 1408 my $Self = shift;
691 1408 my $DateStr = shift;
692 1408 my $TZStr = shift;
693 1408 my $TargetTz = shift;
694  
695 1408 my ($Date, $HasTime) = _vDate($DateStr);
696  
697 # if it's all day, return it immediately
698 1407 ▶ return ($Date, 1) unless $HasTime;
Branch: 1 branch
BranchTrueFalseTotal
unless $HasTime 58 1349 1407
699  
700 # Do the timezone manipulation as required
701 1349 ▶ $Date->set_time_zone($Self->tz($TZStr)) if $TZStr;
Branch: 1 branch
BranchTrueFalseTotal
if $TZStr 1337 12 1349
702 1349 ▶ $Date->set_time_zone($Self->tz($TargetTz)) if $TargetTz;
Branch: 1 branch
BranchTrueFalseTotal
if $TargetTz 624 725 1349
703  
704 1349 return ($Date, 0);
705 }
706  
707 1343 ▶sub _getDateObj {
Subroutine _getDateObj: called CC=2 SCAR=6.9
708 1343 my $Self = shift;
709 1343 my $Calendar = shift;
710 1343 my $VItem = shift;
711 1343 my $TargetTz = shift;
712  
713 1343 my $TimeZone = $Self->_getTimeZone($Calendar, $VItem);
714 1343 my ($Date, $IsAllDay) = $Self->_makeDateObj($VItem->{value}, $TimeZone, $TargetTz);
715  
716 1342 ▶ return (wantarray ? ($Date, $TimeZone, $IsAllDay) : $Date);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 718 624 1342
717 }
718  
719 29 ▶sub _getDateObjMulti {
Subroutine _getDateObjMulti: called CC=4 SCAR=13.9
720 29 my $Self = shift;
721 29 my $Calendar = shift;
722 29 my $VItem = shift;
723 29 my $TargetTz = shift;
724  
725 29 my @Dates;
726  
727 29 my $TimeZone = $Self->_getTimeZone($Calendar, $VItem);
728 29 foreach my $Value (split /,/, $VItem->{value}) {
729 # XXX - handle $V2 sanely
730 30 ▶ if (lc($VItem->{params}{value}[0] || '') eq 'period') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($VItem->{"params"}{"value"}[0] || "") eq "period") 0 30 30
Condition100%2/2
$VItem->{'params'}{'value'}[0] || ''
l!l
723
MC/DC100%1/1
$VItem->{'params'}{'value'}[0] || ''
$VItem->{'params'}{'value'}[0]
Truth table100%2/2
A
A= $VItem->{'params'}{'value'}[0]
Aresult
11
00
731 0 ($Value, my $V2) = split /\//, $Value;
732 }
733 30 my ($Date, $IsAllDay) = $Self->_makeDateObj($Value, $TimeZone, $TargetTz);
734 30 push @Dates, $Date;
735 }
736  
737 29 return @Dates;
738 }
739  
740 # Exclude DTSTAMP from auto uid generation
741 9 ▶sub _hexkey {
Subroutine _hexkey: called CC=3 SCAR=11.1
742 9 my $VEvent = shift;
743 9 ▶ my $extra = shift || '';
Condition50%1/2
shift() || ''
l!l
90
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
744 9 my $updated = delete $VEvent->{properties}->{updated};
745 9 my $d = Data::Dumper->new([$VEvent]);
746 9 $d->Indent(0);
747 9 $d->Sortkeys(1);
748 9 my $Key = sha1_hex($d->Dump() . $extra);
749 9 ▶ $VEvent->{properties}->{updated} = $updated if defined $updated;
Branch: 1 branch
BranchTrueFalseTotal
if defined $updated 0 9 9
750 9 return $Key;
751 }
752  
753 # An iCalendar INTEGER as a number, or undef if it is not one.
754 864 ▶sub _intValue {
Subroutine _intValue: called CC=3 SCAR=11.0
755 864 my $value = shift;
756 864 ▶ return undef unless defined $value and $value =~ /^\s*([-+]?\d+)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /^\s*([-+]?\d+)\s*$/ 578 286 864
Condition100%3/3
defined $value and $value =~ /^\s*([-+]?\d+)\s*$/
!ll&&!rl&&r
5771286
MC/DC100%2/2
defined $value and $value =~ /^\s*([-+]?\d+)\s*$/
defined $value $value =~ /^\s*([-+]?\d+)\s*$/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /^\s*([-+]?\d+)\s*$/
ABresult
0X0
100
111
757 286 return int $1;
758 }
759  
760 437 ▶sub _saneuid {
Subroutine _saneuid: called CC=4 SCAR=14.6
761 437 my $uid = shift;
762 437 ▶ return unless $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless $uid 0 437 437
763 437 ▶ return if $uid =~ m/\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $uid =~ /\s/ 0 437 437
764 437 ▶ return if $uid =~ m/[\x7f-\xff]/;
Branch: 1 branch
BranchTrueFalseTotal
if $uid =~ /[\x7f-\xff]/ 0 437 437
765 # any other sanity checks?
766 437 return 1;
767 }
768  
769 # The key the reader gives a participant whose ATTENDEE/ORGANIZER carries
770 # no JSID: a hash of its address. The writer omits JSID when the key
771 # already matches this (jscalendar-icalendar 2.3.4, 2.3.29).
772 107 ▶sub _defaultParticipantKey {
Subroutine _defaultParticipantKey: called CC=3 SCAR=11.3
773 107 my $uri = shift;
774 107 ▶ return undef unless defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 107 107
775 107 $uri =~ s/^mailto://i;
776 107 ▶ return undef if $uri eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq "" 0 107 107
777 107 return sha1_hex(lc $uri);
778 }
779  
780 # The JSID parameter (jscalendar-icalendar 4.2.1), or the older X-JMAP-ID,
781 # if it is a valid Id (jscalendarbis 1.4.1).
782 432 ▶sub _propJSID {
Subroutine _propJSID: called CC=5 SCAR=16.1
783 432 my $Prop = shift;
784 432 for my $param (qw(jsid x-jmap-id)) {
785 772 ▶ my $id = $Prop->{params}{$param} && $Prop->{params}{$param}[0];
Condition66%2/3
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
!ll&&!rl&&r
6680104
MC/DC50%1/2
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
$Prop->{'params'}{$param} $Prop->{'params'}{$param}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{$param}B= $Prop->{'params'}{$param}[0]
ABresult
0X0
100
111
786 772 ▶ return $id if defined $id and $id =~ m/\A[A-Za-z0-9_-]{1,255}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/ 102 670 772
Condition100%3/3
defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
!ll&&!rl&&r
6682102
MC/DC100%2/2
defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
defined $id $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
Truth table100%3/3
A and B
A= defined $idB= $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
ABresult
0X0
100
111
787 }
788 330 return undef;
789 }
790  
791 # (title => ...) from the first of the named parameters that is set.
792 20 ▶sub _linkTitle {
Subroutine _linkTitle: called CC=5 SCAR=16.3
793 20 my ($Prop, @params) = @_;
794 20 for my $param (@params) {
795 20 ▶ my $v = $Prop->{params}{$param} && $Prop->{params}{$param}[0];
Condition66%2/3
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
!ll&&!rl&&r
8012
MC/DC50%1/2
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
$Prop->{'params'}{$param} $Prop->{'params'}{$param}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{$param}B= $Prop->{'params'}{$param}[0]
ABresult
0X0
100
111
796 20 ▶ return (title => $v) if defined $v && length $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and length $v 12 8 20
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
8012
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
797 }
798 8 return ();
799 }
800  
801 # The SENT-BY parameter of an ATTENDEE or ORGANIZER as an email address
802 # (the "mailto:" dropped), or undef.
803 4 ▶sub _mailto {
Subroutine _mailto: called CC=2 SCAR=7.2
804 4 my $addr = shift;
805 4 ▶ return $addr =~ /^[A-Za-z][A-Za-z0-9+.-]*:/ ? $addr : "mailto:$addr";
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /^[A-Za-z][A-Za-z0-9+.-]*:/ ? : 0 4 4
806 }
807  
808 261 ▶sub _sentByAddress {
Subroutine _sentByAddress: called CC=4 SCAR=14.0
809 261 my $Prop = shift;
810 261 ▶ my $v = $Prop->{params}{'sent-by'} && $Prop->{params}{'sent-by'}[0];
Condition66%2/3
$Prop->{'params'}{'sent-by'} && $Prop->{'params'}{'sent-by'}[0]
!ll&&!rl&&r
25506
MC/DC50%1/2
$Prop->{'params'}{'sent-by'} && $Prop->{'params'}{'sent-by'}[0]
$Prop->{'params'}{'sent-by'} $Prop->{'params'}{'sent-by'}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{'sent-by'}B= $Prop->{'params'}{'sent-by'}[0]
ABresult
0X0
100
111
811 261 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 255 6 261
812 6 $v =~ s/^mailto://i;
813 6 ▶ return length $v ? $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $v ? : 6 0 6
814 }
815  
816 # DELEGATED-FROM and DELEGATED-TO are lists of quoted cal-addresses
817 # (RFC 5545 3.2.4, 3.2.5), which the parser hands back joined with commas.
818 # Split them again, but only before something that starts a URI, so a
819 # comma inside an address survives.
820 13 ▶sub _splitCalAddresses {
Subroutine _splitCalAddresses: called CC=1 SCAR=0.0
821 13 return grep { length } map { split /,(?=[A-Za-z][A-Za-z0-9+.-]*:)/ } grep { defined } @_;
822 }
823  
824 194 ▶sub _makeParticipant {
Subroutine _makeParticipant: called CC=33 SCAR=35.9
825 194 my ($Self, $Calendar, $Participants, $VAttendee, $role, $AddrKeys) = @_;
826  
827 194 my $email = $VAttendee->{value};
828 194 ▶ return unless $email;
Branch: 1 branch
BranchTrueFalseTotal
unless $email 0 194 194
829 194 $email =~ s/^mailto://i;
830 194 ▶ return if $email eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $email eq "" 0 194 194
831 # jscalendar-icalendar 2.1.3: a JSID MUST be used as the key. ORGANIZER
832 # and ATTENDEE with the same address are one participant, so a JSID on
833 # either of them keys both.
834 my $id = _propJSID($VAttendee)
835 194 ▶ // ($AddrKeys && $AddrKeys->{lc $email})
Condition55%5/9
(_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}) // &sha1_hex(lc $email)
l!l&&r!l&&!r
391550
_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}
l!l&&r!l&&!r
390155
$AddrKeys and $$AddrKeys{lc $email}
!ll&&!rl&&r
01550
MC/DC0%0/4
(_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}) // &sha1_hex(lc $email)
_propJSID($VAttendee) $AddrKeys $$AddrKeys{lc $email} &sha1_hex(lc $email)
Truth table33%2/6
A // B and C // D
A= _propJSID($VAttendee)B= $AddrKeysC= $$AddrKeys{lc $email}D= &sha1_hex(lc $email)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
836 // sha1_hex(lc $email);
837  
838 194 ▶ $Participants->{$id} ||= {};
Condition100%2/2
$Participants->{$id} ||= {}
l!l
35159
MC/DC100%1/1
$Participants->{$id} ||= {}
$Participants->{$id}
Truth table100%2/2
A
A= $Participants->{$id}
Aresult
11
00
839  
840 # XXX - if present on one but not the other, take the "best" version
841 194 ▶ $Participants->{$id}{name} = $VAttendee->{params}{"cn"}[0] // "";
Condition100%2/2
$VAttendee->{"params"}{"cn"}[0] // ""
l!l
13460
MC/DC100%1/1
$VAttendee->{"params"}{"cn"}[0] // ""
$VAttendee->{"params"}{"cn"}[0]
Truth table100%2/2
A
A= $VAttendee->{"params"}{"cn"}[0]
Aresult
11
00
842 194 ▶ $Participants->{$id}{email} = $VAttendee->{params}{"email"}[0] // $email;
Condition33%1/3
$VAttendee->{"params"}{"email"}[0] // $email
l!l&&r!l&&!r
01940
MC/DC0%0/2
$VAttendee->{"params"}{"email"}[0] // $email
$VAttendee->{"params"}{"email"}[0] $email
Truth table33%1/3
A // B
A= $VAttendee->{"params"}{"email"}[0]B= $email
ABresult
1X1
011
000
843 194 $Participants->{$id}{calendarAddress} = "mailto:$email";
844 $Participants->{$id}{kind} = lc $VAttendee->{params}{"cutype"}[0]
845 194 ▶ if $VAttendee->{params}{"cutype"};
Branch: 1 branch
BranchTrueFalseTotal
if $VAttendee->{"params"}{"cutype"} 10 184 194
846 194 $Participants->{$id}{roles}{$role} = $JSON::true;
847 # we don't support locationId yet
848 194 ▶ if ($VAttendee->{params}{"partstat"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"partstat"}) 79 115 194
849 79 ▶ $Participants->{$id}{participationStatus} = lc($VAttendee->{params}{"partstat"}[0] // "needs-action");
Condition50%1/2
$VAttendee->{"params"}{"partstat"}[0] // "needs-action"
l!l
790
MC/DC0%0/1
$VAttendee->{"params"}{"partstat"}[0] // "needs-action"
$VAttendee->{"params"}{"partstat"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"partstat"}[0]
Aresult
11
00
850 }
851 194 ▶ if ($VAttendee->{params}{"role"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"role"}) 47 147 194
852 47 ▶ my $ical_role = uc($VAttendee->{params}{"role"}[0] || '');
Condition50%1/2
$VAttendee->{'params'}{'role'}[0] || ''
l!l
470
MC/DC0%0/1
$VAttendee->{'params'}{'role'}[0] || ''
$VAttendee->{'params'}{'role'}[0]
Truth table50%1/2
A
A= $VAttendee->{'params'}{'role'}[0]
Aresult
11
00
853 47 ▶ if ($ical_role eq 'CHAIR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ical_role eq "CHAIR") 4 43 47
854 4 $Participants->{$id}{roles}{chair} = $JSON::true;
855 }
856  
857 47 ▶ if ($ical_role eq 'OWNER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ical_role eq "OWNER") 27 20 47
858 27 $Participants->{$id}{roles}{owner} = $JSON::true;
859 }
860  
861 47 ▶ $Participants->{$id}{roles}{optional} = $JSON::true
Branch: 1 branch
BranchTrueFalseTotal
if $ical_role eq "OPT-PARTICIPANT" 11 36 47
862 if $ical_role eq 'OPT-PARTICIPANT';
863  
864 47 ▶ $Participants->{$id}{roles}{informational} = $JSON::true
Branch: 1 branch
BranchTrueFalseTotal
if $ical_role eq "NON-PARTICIPANT" 1 46 47
865 if $ical_role eq 'NON-PARTICIPANT';
866 }
867 194 ▶ if ($VAttendee->{params}{"rsvp"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"rsvp"}) 12 182 194
868 12 ▶ $Participants->{$id}{expectReply} = lc($VAttendee->{params}{"rsvp"}[0] // "") eq 'yes' ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
lc($VAttendee->{'params'}{'rsvp'}[0] // '') eq 'yes' ? : 0 12 12
Condition50%1/2
$VAttendee->{"params"}{"rsvp"}[0] // ""
l!l
120
MC/DC0%0/1
$VAttendee->{"params"}{"rsvp"}[0] // ""
$VAttendee->{"params"}{"rsvp"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"rsvp"}[0]
Aresult
11
00
869 }
870 # SENT-BY is a cal-address; sentBy an email address (jscalendarbis-22
871 # 3.4.6, jscalendar-icalendar-29 2.3.4, 2.3.29)
872 194 ▶ if (my $SentBy = _sentByAddress($VAttendee)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $SentBy = _sentByAddress($VAttendee)) 4 190 194
873 4 $Participants->{$id}{sentBy} = $SentBy;
874 }
875 194 ▶ if (exists $VAttendee->{params}{"x-dtstamp"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VAttendee->{"params"}{"x-dtstamp"}) 17 177 194
876 17 my ($Date) = eval { $Self->_makeDateObj($VAttendee->{params}{"x-dtstamp"}[0], 'UTC', 'UTC') };
877 17 ▶ $Participants->{$id}{"scheduleUpdated"} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 17 0 17
878 }
879 # memberOf is not supported
880  
881 194 ▶ if (exists $VAttendee->{params}{"x-sequence"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VAttendee->{"params"}{"x-sequence"}) 5 189 194
882 5 ▶ $Participants->{$id}{scheduleSequence} = $VAttendee->{params}{"x-sequence"}[0] // "";
Condition50%1/2
$VAttendee->{"params"}{"x-sequence"}[0] // ""
l!l
50
MC/DC0%0/1
$VAttendee->{"params"}{"x-sequence"}[0] // ""
$VAttendee->{"params"}{"x-sequence"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"x-sequence"}[0]
Aresult
11
00
883 }
884  
885 194 ▶ if ($VAttendee->{params}{"schedule-agent"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"schedule-agent"}) 1 193 194
886 1 $Participants->{$id}{scheduleAgent} = lc($VAttendee->{params}{"schedule-agent"}[0]);
887 }
888  
889 194 ▶ if ($VAttendee->{params}{"delegated-from"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"delegated-from"}) 6 188 194
890 6 my %df;
891 6 for my $uri (_splitCalAddresses(@{$VAttendee->{params}{"delegated-from"}})) {
892 6 $df{$uri} = $JSON::true;
893 }
894 6 ▶ $Participants->{$id}{delegatedFrom} = \%df if %df;
Branch: 1 branch
BranchTrueFalseTotal
if %df 6 0 6
895 }
896  
897 194 ▶ if ($VAttendee->{params}{"delegated-to"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"delegated-to"}) 7 187 194
898 7 my %dt;
899 7 for my $uri (_splitCalAddresses(@{$VAttendee->{params}{"delegated-to"}})) {
900 9 $dt{$uri} = $JSON::true;
901 }
902 7 ▶ $Participants->{$id}{delegatedTo} = \%dt if %dt;
Branch: 1 branch
BranchTrueFalseTotal
if %dt 7 0 7
903 }
904 }
905  
906 513 ▶sub _make_duration {
Subroutine _make_duration: called CC=15 SCAR=27.3
907 513 my ($Self, $dtdur, $IsAllDay) = @_;
908  
909 513 my ($w, $d, $H, $M, $S) = (
910 $dtdur->weeks,
911 $dtdur->days,
912 $dtdur->hours,
913 $dtdur->minutes,
914 $dtdur->seconds,
915 );
916  
917 513 ▶ return 'PT0S' unless ($w || $d || $H || $M || $S);
Branch: 1 branch
BranchTrueFalseTotal
unless $w or $d or $H or $M or $S 207 306 513
Condition83%10/12
$w or $d or $H or $M or $S
l!l&&r!l&&!r
3060207
$w or $d or $H or $M
l!l&&r!l&&!r
23670207
$w or $d or $H
l!l&&r!l&&!r
23213277
$w or $d
l!l&&r!l&&!r
023490
MC/DC60%3/5
$w or $d or $H or $M or $S
$w $d $H $M $S
Truth table66%4/6
A or B or C or D or E
A= $wB= $dC= $HD= $ME= $S
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
918  
919 306 my @bits = ('P');
920 306 ▶ push @bits, ($w, 'W') if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 306 306
921 306 ▶ push @bits, ($d, 'D') if $d;
Branch: 1 branch
BranchTrueFalseTotal
if $d 23 283 306
922 306 ▶ if (not $IsAllDay and ($H || $M || $S)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $H || $M || $S) 286 20 306
Condition88%8/9
not $IsAllDay and $H || $M || $S
!ll&&!rl&&r
191286
$H or $M or $S
l!l&&r!l&&!r
28601
$H or $M
l!l&&r!l&&!r
216701
MC/DC75%3/4
not $IsAllDay and $H || $M || $S
not $IsAllDay $H $M $S
Truth table80%4/5
not(A) and B or C or D
A= not $IsAllDayB= $HC= $MD= $S
ABCDresult
0XXX0
10000
11XX1
101X1
10011
923 286 push @bits, 'T';
924 286 ▶ push @bits, ($H, 'H') if $H;
Branch: 1 branch
BranchTrueFalseTotal
if $H 216 70 286
925 286 ▶ push @bits, ($M, 'M') if $M;
Branch: 1 branch
BranchTrueFalseTotal
if $M 76 210 286
926 286 ▶ push @bits, ($S, 'S') if $S;
Branch: 1 branch
BranchTrueFalseTotal
if $S 0 286 286
927 }
928  
929 306 return join ('', @bits);
930 }
931  
932 =head2 $NewEvent = Text::JSCalendar->NormaliseEvent($Event);
933  
934 Returns a copy of the event (the original is not changed) in a canonical
935 form for comparison: every property whose value is its default
936 (jscalendarbis-22, or RFC 8984 for the properties -22 reserved) is
937 removed, and so is an C<@type> that only repeats the type its position
938 already implies. Empty maps and arrays are removed. Everything else is
939 kept as it is: a property this module does not know, the contents of a
940 C<recurrenceOverrides> patch, and the C<@type> of the Event or Task and of
941 any trigger that is not an OffsetTrigger.
942  
943 Inside a recurrence override, a patch whose path names a known object
944 (C<participants/p1>, C<alerts/a1/trigger>, C<locations>) has that object
945 normalised the same way. A patched value is never removed for being the
946 default: in a patch it overrides the master, so C<"status": "confirmed">
947 says something that C<{}> does not.
948  
949 =cut
950  
951 # The @type an object may leave out because its position implies it
952 # (jscalendarbis-22 1.4.4). The Event or Task itself is absent here: there
953 # @type says which of the two it is. For a trigger this is the defaultType
954 # (3.5.1); an AbsoluteTrigger or unknown trigger keeps its @type.
955 18 my %ImpliedType = (
956 links => 'Link',
957 locations => 'Location',
958 virtualLocations => 'VirtualLocation',
959 recurrenceRule => 'RecurrenceRule',
960 byDay => 'NDay',
961 relatedTo => 'Relation',
962 participants => 'Participant',
963 alerts => 'Alert',
964 trigger => 'OffsetTrigger',
965 );
966  
967 213 ▶sub NormaliseEvent {
Subroutine NormaliseEvent: called CC=11 SCAR=24.0
Pod documented
968 213 my ($class, $Event, $Root) = @_;
969  
970 213 ▶ $Root ||= '';
Condition100%2/2
$Root ||= ""
l!l
13677
MC/DC100%1/1
$Root ||= ""
$Root
Truth table100%2/2
A
A= $Root
Aresult
11
00
971  
972 213 my %Copy = %$Event;
973  
974 213 ▶ if (exists $Copy{'@type'} and defined $ImpliedType{$Root}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})) 85 128 213
Condition100%6/6
exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
!ll&&!rl&&r
121785
exists $Copy{"\@type"} and defined $ImpliedType{$Root}
!ll&&!rl&&r
447792
MC/DC100%3/3
exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
exists $Copy{"\@type"} defined $ImpliedType{$Root} _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
Truth table100%4/4
A and B and C
A= exists $Copy{"\@type"}B= defined $ImpliedType{$Root}C= _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
ABCresult
0XX0
10X0
1100
1111
975 and _safeeq($Copy{'@type'}, $ImpliedType{$Root})) {
976 85 delete $Copy{'@type'};
977 }
978  
979 # An AbsoluteTrigger or an unknown trigger: nothing below applies to it
980 # (relativeTo's default is the OffsetTrigger's), so keep it as it is.
981 213 ▶ return \%Copy if $Root eq 'trigger' and exists $Copy{'@type'};
Branch: 1 branch
BranchTrueFalseTotal
if $Root eq "trigger" and exists $Copy{"\@type"} 7 206 213
Condition100%3/3
$Root eq "trigger" and exists $Copy{"\@type"}
!ll&&!rl&&r
191157
MC/DC100%2/2
$Root eq "trigger" and exists $Copy{"\@type"}
$Root eq "trigger" exists $Copy{"\@type"}
Truth table100%3/3
A and B
A= $Root eq "trigger"B= exists $Copy{"\@type"}
ABresult
0X0
100
111
982  
983 # Only the keys the table knows are normalised; any other key is kept.
984 # (This used to delete every key not in the table, which wiped the
985 # contents of override patches and triggers, and every @type.)
986 206 ▶ my $Spec = $EventKeys{$Root} || {};
Condition50%1/2
$EventKeys{$Root} || {}
l!l
2060
MC/DC0%0/1
$EventKeys{$Root} || {}
$EventKeys{$Root}
Truth table50%1/2
A
A= $EventKeys{$Root}
Aresult
11
00
987 206 foreach my $key (sort keys %$Spec) {
988 4084 ▶ next unless exists $Copy{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Copy{$key} 2987 1097 4084
989 1097 my ($keep, $value) = $class->_normaliseProp($Spec->{$key}, $key, $Copy{$key});
990 1097 ▶ if ($keep) { $Copy{$key} = $value }
Branch: 1 branch
BranchTrueFalseTotal
if ($keep) { } 990 107 1097
991 107 else { delete $Copy{$key} }
992 }
993  
994 206 return \%Copy;
995 }
996  
997 # Normalise one property value under its %EventKeys entry. Returns
998 # (1, $value) to keep it, or () to drop it as default or empty.
999 1097 ▶sub _normaliseProp {
Subroutine _normaliseProp: called CC=13 SCAR=26.2
1000 1097 my ($class, $entry, $key, $value) = @_;
1001 1097 my ($container, $type, undef, $default) = @$entry;
1002  
1003 1097 ▶ if ($container) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container) 99 998 1097
1004 # a map or array: null and empty are both "not set"
1005 99 ▶ return () unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 99 99
1006 99 my @new = $class->_normaliseContainer($entry, $key, $value);
1007 99 ▶ return @new ? (1, $new[0]) : ();
Branch: 1 branch
BranchTrueFalseTotal
@new ? : 99 0 99
1008 }
1009  
1010 998 ▶ if ($type eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 39 959 998
1011 39 ▶ return (1, $value) unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 39 39
1012 39 return (1, $class->NormaliseEvent($value, $key));
1013 }
1014 # not the shape we expect: keep it (a JSON boolean is a scalar here)
1015 959 ▶ return (1, $value) if ref($value) and not JSON::is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and not &JSON::is_bool($value) 10 949 959
Condition100%3/3
ref $value and not &JSON::is_bool($value)
!ll&&!rl&&r
9034610
MC/DC100%2/2
ref $value and not &JSON::is_bool($value)
ref $value not &JSON::is_bool($value)
Truth table100%3/3
A and not(B)
A= ref $valueB= not &JSON::is_bool($value)
ABresult
0X0
100
111
1016 949 ▶ if ($type eq 'bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "bool") 46 903 949
1017 46 ▶ return () if !!$default == !!$value;
Branch: 1 branch
BranchTrueFalseTotal
if !!$default == !!$value 44 2 46
1018 2 return (1, $value);
1019 }
1020 903 ▶ if ($type eq 'mailto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "mailto") 0 903 903
1021 0 ▶ return (1, $value ? lc $value : $value);
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
1022 }
1023 903 ▶ return () if _safeeq($default, $value);
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($default, $value) 63 840 903
1024 840 return (1, $value);
1025 }
1026  
1027 # The members of a map (container 2) or array (container 1). An empty
1028 # one is dropped (()), a malformed one kept as it is.
1029 105 ▶sub _normaliseContainer {
Subroutine _normaliseContainer: called CC=10 SCAR=24.3
1030 105 my ($class, $entry, $key, $value, $keepEmpty) = @_;
1031 105 my ($container) = @$entry;
1032  
1033 105 ▶ if ($container == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container == 2) 98 7 105
1034 98 ▶ return $value unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 98 98
1035 98 ▶ return $value if !%$value and $keepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if not %$value and $keepEmpty 1 97 98
Condition66%2/3
not %$value and $keepEmpty
!ll&&!rl&&r
9701
MC/DC50%1/2
not %$value and $keepEmpty
not %$value $keepEmpty
Truth table66%2/3
not(A) and B
A= not %$valueB= $keepEmpty
ABresult
0X0
100
111
1036 97 ▶ return () unless %$value;
Branch: 1 branch
BranchTrueFalseTotal
unless %$value 0 97 97
1037 97 my %new = map { $_ => $class->_normaliseMember($entry, $key, $value->{$_}) } keys %$value;
1038 97 return \%new;
1039 }
1040  
1041 7 ▶ return $value unless ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 7 7
1042 7 ▶ return $value if !@$value and $keepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if not @$value and $keepEmpty 0 7 7
Condition33%1/3
not @$value and $keepEmpty
!ll&&!rl&&r
700
MC/DC0%0/2
not @$value and $keepEmpty
not @$value $keepEmpty
Truth table33%1/3
not(A) and B
A= not @$valueB= $keepEmpty
ABresult
0X0
100
111
1043 7 ▶ return () unless @$value;
Branch: 1 branch
BranchTrueFalseTotal
unless @$value 0 7 7
1044 7 return [ map { $class->_normaliseMember($entry, $key, $_) } @$value ];
1045 }
1046  
1047 # One member of a map or array: an object or a patch is normalised, any
1048 # other value (a boolean in a set, a string) is kept.
1049 164 ▶sub _normaliseMember {
Subroutine _normaliseMember: called CC=4 SCAR=14.0
1050 164 my ($class, $entry, $key, $value) = @_;
1051 164 my $type = $entry->[1];
1052 164 ▶ return $value unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 49 115 164
1053 115 ▶ return $class->NormaliseEvent($value, $key) if $type eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "object" 96 19 115
1054 19 ▶ return $class->_normalisePatch($value) if $type eq 'patch';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "patch" 19 0 19
1055 0 return $value;
1056 }
1057  
1058 # A PatchObject (jscalendarbis-22 1.4.9). Each path that resolves to a
1059 # known object position has its value normalised as that object; a value
1060 # is never dropped (a patch setting a default overrides the master), and
1061 # a path that does not resolve is kept untouched.
1062 19 ▶sub _normalisePatch {
Subroutine _normalisePatch: called CC=10 SCAR=23.7
1063 19 my ($class, $Patch) = @_;
1064  
1065 19 my %new;
1066 19 foreach my $path (keys %$Patch) {
1067 32 my $value = $Patch->{$path};
1068 32 my ($where, $entry, $key) = _patchTarget($path);
1069 32 ▶ if (!$where or ref($value) ne 'HASH' && ref($value) ne 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (not $where or ref $value ne 'HASH' and ref $value ne 'ARRAY') { } 24 8 32
elsif ($where eq 'member') { } 1 7 8
elsif ($entry->[0]) { } 6 1 7
elsif ($entry->[1] eq 'object' and ref $value eq 'HASH') { } 1 0 1
Condition83%5/6
not $where or ref $value ne "HASH" and ref $value ne "ARRAY"
l!l&&r!l&&!r
5198
ref $value ne "HASH" and ref $value ne "ARRAY"
!ll&&!rl&&r
8019
MC/DC66%2/3
not $where or ref $value ne "HASH" and ref $value ne "ARRAY"
not $where ref $value ne "HASH" ref $value ne "ARRAY"
Truth table75%3/4
not(A) or B and C
A= not $whereB= ref $value ne "HASH"C= ref $value ne "ARRAY"
ABCresult
1XX1
0111
00X0
0100
1070 24 $new{$path} = $value;
1071 }
1072 elsif ($where eq 'member') {
1073 # participants/p1, byDay/0: one object of the map or array
1074 1 ▶ $new{$path} = $entry->[1] eq 'object'
Branch: 1 branch
BranchTrueFalseTotal
$entry->[1] eq 'object' ? : 1 0 1
1075 ? $class->_normaliseMember($entry, $key, $value) : $value;
1076 }
1077 elsif ($entry->[0]) {
1078 # a whole map or array: an empty one is still a patch
1079 6 $new{$path} = $class->_normaliseContainer($entry, $key, $value, 1);
1080 }
1081 ▶ elsif ($entry->[1] eq 'object' and ref($value) eq 'HASH') {
Condition33%1/3
$entry->[1] eq "object" and ref $value eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
$entry->[1] eq "object" and ref $value eq "HASH"
$entry->[1] eq "object" ref $value eq "HASH"
Truth table33%1/3
A and B
A= $entry->[1] eq "object"B= ref $value eq "HASH"
ABresult
0X0
100
111
1082 1 $new{$path} = $class->NormaliseEvent($value, $key);
1083 }
1084 else {
1085 0 $new{$path} = $value;
1086 }
1087 }
1088  
1089 19 return \%new;
1090 }
1091  
1092 # Where a patch path points in %EventKeys: ('prop', $entry, $name) for a
1093 # property, ('member', $entry, $name) for one member of a map or array
1094 # property, or () when it is not a position the table describes.
1095 32 ▶sub _patchTarget {
Subroutine _patchTarget: called CC=9 SCAR=23.0
1096 32 my $path = shift;
1097 32 my @segs = map { _unquotekey($_) } split m{/}, $path, -1;
1098 32 my $table = '';
1099 32 ▶ while (@segs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@segs) 34 0 34
1100 34 my $name = shift @segs;
1101 34 ▶ my $entry = ($EventKeys{$table} || {})->{$name} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $entry = +($EventKeys{$table} || {})->{$name} or return () 29 5 34
Condition50%1/2
$EventKeys{$table} || {}
l!l
340
MC/DC0%0/1
$EventKeys{$table} || {}
$EventKeys{$table}
Truth table50%1/2
A
A= $EventKeys{$table}
Aresult
11
00
1102 29 ▶ return ('prop', $entry, $name) unless @segs;
Branch: 1 branch
BranchTrueFalseTotal
unless @segs 26 3 29
1103 3 ▶ if ($entry->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->[0]) 3 0 3
1104 3 shift @segs; # the map key or array index
1105 3 ▶ return ('member', $entry, $name) unless @segs;
Branch: 1 branch
BranchTrueFalseTotal
unless @segs 1 2 3
1106 }
1107 # deeper in: only into an object with a table of its own
1108 2 ▶ return () unless $entry->[1] eq 'object' and $EventKeys{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->[1] eq "object" and $EventKeys{$name} 0 2 2
Condition33%1/3
$entry->[1] eq "object" and $EventKeys{$name}
!ll&&!rl&&r
002
MC/DC0%0/2
$entry->[1] eq "object" and $EventKeys{$name}
$entry->[1] eq "object" $EventKeys{$name}
Truth table33%1/3
A and B
A= $entry->[1] eq "object"B= $EventKeys{$name}
ABresult
0X0
100
111
1109 2 $table = $name;
1110 }
1111 0 return ();
1112 }
1113  
1114 =head2 Text::JSCalendar->CompareEvents($Event1, $Event2);
1115  
1116 Returns true if the events are the same once normalised (see
1117 C<NormaliseEvent>).
1118  
1119 =cut
1120  
1121 7 ▶sub CompareEvents {
Subroutine CompareEvents: called CC=1 SCAR=0.0
Pod documented
1122 7 my ($class, $Event1, $Event2) = @_;
1123  
1124 7 my $E1 = $class->NormaliseEvent($Event1);
1125 7 my $E2 = $class->NormaliseEvent($Event2);
1126  
1127 7 return _safeeq($E1, $E2);
1128 }
1129  
1130 392 ▶sub _getEventsFromVCalendar {
Subroutine _getEventsFromVCalendar: called CC=11 SCAR=24.1
1131 392 my ($Self, $VCalendar) = @_;
1132  
1133 392 ▶ my $CalendarData = eval { vcard2hash($VCalendar, multival => ['rrule'], only_one => 1) }
Branch: 1 branch
BranchTrueFalseTotal
my $CalendarData = eval { do { vcard2hash($VCalendar, "multival", ["rrule"], "only_one", 1) } } or confess("Error parsing VCalendar data: $@\n\n$VCalendar") 392 0 392
1134 or confess "Error parsing VCalendar data: $@\n\n$VCalendar";
1135  
1136 392 my @Events;
1137  
1138 392 ▶ foreach my $Calendar (@{$CalendarData->{objects} || []}) {
Condition50%1/2
$CalendarData->{'objects'} || []
l!l
3920
MC/DC0%0/1
$CalendarData->{'objects'} || []
$CalendarData->{'objects'}
Truth table50%1/2
A
A= $CalendarData->{'objects'}
Aresult
11
00
1139 392 ▶ next unless lc $Calendar->{type} eq 'vcalendar';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $Calendar->{"type"} eq "vcalendar" 0 392 392
1140  
1141 392 my $method = $Calendar->{properties}{method}[0]{value};
1142 392 my $prodid = $Calendar->{properties}{prodid}[0]{value};
1143  
1144 392 ▶ foreach my $VEvent (@{$Calendar->{objects} || []}) {
Condition100%2/2
$Calendar->{'objects'} || []
l!l
38210
MC/DC100%1/1
$Calendar->{'objects'} || []
$Calendar->{'objects'}
Truth table100%2/2
A
A= $Calendar->{'objects'}
Aresult
11
00
1145 546 ▶ my $type = lc($VEvent->{type} // '');
Condition50%1/2
$VEvent->{"type"} // ""
l!l
5460
MC/DC0%0/1
$VEvent->{"type"} // ""
$VEvent->{"type"}
Truth table50%1/2
A
A= $VEvent->{"type"}
Aresult
11
00
1146 546 ▶ next unless $type eq 'vevent' || $type eq 'vtodo';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "vevent" or $type eq "vtodo" 109 437 546
Condition100%3/3
$type eq "vevent" or $type eq "vtodo"
l!l&&r!l&&!r
41522109
MC/DC100%2/2
$type eq "vevent" or $type eq "vtodo"
$type eq "vevent" $type eq "vtodo"
Truth table100%3/3
A or B
A= $type eq "vevent"B= $type eq "vtodo"
ABresult
1X1
011
000
1147 # each component on its own: one that cannot be converted is
1148 # dropped (and reported by errors()), not the whole calendar
1149 437 my $Event = eval { $Self->_vEventToEvent($Calendar, $VEvent, $method, $prodid) };
1150 437 ▶ if ($Event) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Event) { } 426 11 437
1151 426 push @Events, $Event;
1152 }
1153 else {
1154 11 $Self->_error($VEvent->{properties}{uid}[0]{value}, uc $type, $@);
1155 }
1156 }
1157 }
1158  
1159 392 return \@Events;
1160 }
1161  
1162 # One VEVENT or VTODO as an Event or Task. Dies if it cannot be
1163 # converted; a bad VALARM or RRULE in it is dropped and reported instead.
1164 437 ▶sub _vEventToEvent {
Subroutine _vEventToEvent: called CC=237 SCAR=60.0
1165 437 my ($Self, $Calendar, $VEvent, $method, $prodid) = @_;
1166  
1167 437 my $is_task = lc $VEvent->{type} eq 'vtodo';
1168  
1169 # parse simple component properties {{{
1170  
1171 my %Properties
1172 3136 = map { $_ => $VEvent->{properties}{$_}[0] }
1173 437 keys %{$VEvent->{properties}};
1174  
1175 437 my $uid = $Properties{uid}{value};
1176 # Case: UID is badly broken or missing -
1177 # let's just calculate a UID based on the incoming data. This
1178 # is the 'ICS sync url with no UIDs in it' case from BTS-3205,
1179 # http://mozorg.cdn.mozilla.net/media/caldata/DutchHolidays.ics
1180 437 ▶ $uid = _hexkey($VEvent) . '-syncauto' unless _saneuid($uid);
Branch: 1 branch
BranchTrueFalseTotal
unless _saneuid($uid) 0 437 437
1181  
1182 437 ▶ my $ShowAsFree = (lc($Properties{transp}{value} || '')) eq 'transparent';
Condition100%2/2
$Properties{'transp'}{'value'} || ''
l!l
287150
MC/DC100%1/1
$Properties{'transp'}{'value'} || ''
$Properties{'transp'}{'value'}
Truth table100%2/2
A
A= $Properties{'transp'}{'value'}
Aresult
11
00
1183  
1184 # clean up whitespace on text fields
1185 437 foreach my $Property (qw{description location summary}) {
1186 1311 ▶ next unless defined $Properties{$Property}{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Properties{$Property}{"value"} 954 357 1311
1187 357 $Properties{$Property}{value} =~ s/^\s+//gs;
1188 357 $Properties{$Property}{value} =~ s/\s+$//gs;
1189 }
1190  
1191 437 my @description;
1192 push @description, $Properties{description}{value}
1193 437 ▶ if defined $Properties{description}{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Properties{"description"}{"value"} 88 349 437
1194  
1195 # }}}
1196  
1197 # parse time component properties {{{
1198  
1199 437 my ($IsAllDay, $Start, $StartTimeZone, $End, $EndTimeZone) = ('') x 5;
1200  
1201 437 ▶ confess "$uid: DTSTART not specified" unless defined $Properties{dtstart}{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Properties{"dtstart"}{"value"} 10 427 437
1202  
1203 427 ($Start, $StartTimeZone, $IsAllDay) = $Self->_getDateObj($Calendar, $Properties{dtstart});
1204  
1205 426 ▶ if (defined $Properties{dtend}{value}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $Properties{'dtend'}{'value'}) { } 284 142 426
elsif (defined $Properties{'duration'}{'value'}) { } 20 122 142
1206 284 ▶ if (defined $Properties{duration}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Properties{"duration"}{"value"}) 1 283 284
1207 1 $Self->_warning($uid, uc $VEvent->{type}, "DTEND and DURATION cannot both be set; DURATION ignored");
1208 }
1209  
1210 284 ($End, $EndTimeZone) = $Self->_getDateObj($Calendar, $Properties{dtend});
1211 }
1212 elsif (defined $Properties{duration}{value}) {
1213 20 my $Duration = DateTime::Format::ICal->parse_duration(uc $Properties{duration}{value});
1214 20 $End = $Start->clone()->add($Duration);
1215 20 $EndTimeZone = $StartTimeZone;
1216 }
1217 else {
1218 122 $End = $Start->clone();
1219 122 $EndTimeZone = $StartTimeZone;
1220 }
1221  
1222 426 ▶ if (DateTime->compare($Start, $End) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($Start, $End) > 0) 0 426 426
1223 # swap em!
1224 0 ($Start, $End) = ($End, $Start);
1225 0 ($StartTimeZone, $EndTimeZone) = ($EndTimeZone, $StartTimeZone);
1226 }
1227  
1228 426 ▶ if ($IsAllDay and $StartTimeZone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay and $StartTimeZone) 0 426 426
Condition66%2/3
$IsAllDay and $StartTimeZone
!ll&&!rl&&r
402240
MC/DC0%0/2
$IsAllDay and $StartTimeZone
$IsAllDay $StartTimeZone
Truth table66%2/3
A and B
A= $IsAllDayB= $StartTimeZone
ABresult
0X0
100
111
1229 0 $Self->_warning($uid, uc $VEvent->{type}, "all-day DTSTART with time zone $StartTimeZone");
1230 }
1231  
1232 # if one is set, make sure they are both set
1233 426 ▶ $StartTimeZone ||= $EndTimeZone;
Condition66%2/3
$StartTimeZone ||= $EndTimeZone
l!l&&r!l&&!r
394032
MC/DC50%1/2
$StartTimeZone ||= $EndTimeZone
$StartTimeZone $EndTimeZone
Truth table66%2/3
A ||= B
A= $StartTimeZoneB= $EndTimeZone
ABresult
1X1
011
000
1234 426 ▶ $EndTimeZone ||= $StartTimeZone;
Condition66%2/3
$EndTimeZone ||= $StartTimeZone
l!l&&r!l&&!r
394032
MC/DC50%1/2
$EndTimeZone ||= $StartTimeZone
$EndTimeZone $StartTimeZone
Truth table66%2/3
A ||= B
A= $EndTimeZoneB= $StartTimeZone
ABresult
1X1
011
000
1235  
1236 # }}}
1237  
1238 426 my %Recurrence;
1239  
1240 426 ▶ if (exists $Properties{rrule}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Properties{"rrule"}) 60 366 426
1241 # a rule that cannot be read drops only itself (see errors())
1242 60 my $ok = eval {
1243 60 my %RRULE;
1244  
1245 60 foreach my $RRULE (@{$Properties{rrule}{values}}) {
1246 157 my ($Key,$Value) = split '=', $RRULE;
1247 157 ▶ next unless defined $Value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Value 0 157 157
1248  
1249 157 $RRULE{lc $Key} = $Value;
1250 }
1251  
1252 # parse simple recurrence properties {{{
1253  
1254 60 ▶ if (exists $RRULE{freq}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{'freq'}) { } 60 0 60
1255 60 my $freq = lc $RRULE{freq};
1256 60 ▶ unless ($ValidFrequency{$freq}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidFrequency{$freq}) 2 58 60
1257 2 confess "$uid: Invalid recurrence FREQ ($freq)";
1258 }
1259  
1260 58 $Recurrence{frequency} = $freq;
1261 }
1262 else {
1263 0 confess "$uid: Recurrence FREQ not specified";
1264 }
1265  
1266 58 ▶ if (exists $RRULE{interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"interval"}) 8 50 58
1267 8 ▶ unless ($RRULE{interval} =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RRULE{"interval"} =~ /^\d+$/) 0 8 8
1268 0 confess "$uid: Invalid recurrence INTERVAL ($RRULE{interval})";
1269 }
1270 8 my $interval = int $RRULE{interval};
1271  
1272 8 ▶ if ($interval == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval == 0) 0 8 8
1273 0 confess "$uid: Recurrence INTERVAL is out of range ($RRULE{interval})";
1274 }
1275  
1276 # default == 1, so don't set a key for it
1277 8 ▶ if ($interval > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval > 1) 8 0 8
1278 8 $Recurrence{interval} = $interval;
1279 }
1280 }
1281  
1282 58 ▶ if (exists $RRULE{rscale}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"rscale"}) 14 44 58
1283 14 $Recurrence{rscale} = lc $RRULE{rscale};
1284 14 ▶ $Recurrence{skip} = lc $RRULE{skip} if $RRULE{skip};
Branch: 1 branch
BranchTrueFalseTotal
if $RRULE{"skip"} 14 0 14
1285 }
1286  
1287 58 ▶ if (exists $RRULE{wkst}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"wkst"}) 1 57 58
1288 1 my $wkst = lc $RRULE{wkst};
1289 1 ▶ unless ($ValidDay{$wkst}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{$wkst}) 0 1 1
1290 0 confess "$uid: Invalid recurrence WKST ($wkst)";
1291 }
1292  
1293 # default is Monday, so don't set a key for it
1294 1 ▶ if ($wkst ne 'mo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($wkst ne "mo") 1 0 1
1295 1 $Recurrence{firstDayOfWeek} = $wkst;
1296 }
1297 }
1298  
1299 58 ▶ if (exists $RRULE{byday}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"byday"}) 15 43 58
1300 15 my @byDays;
1301  
1302 15 foreach my $BYDAY (split ',', $RRULE{byday}) {
1303 43 push @byDays, _BYDAY2byDay(lc $BYDAY);
1304 }
1305  
1306 15 ▶ $Recurrence{byDay} = \@byDays if @byDays;
Branch: 1 branch
BranchTrueFalseTotal
if @byDays 15 0 15
1307 }
1308  
1309 58 ▶ if (exists $RRULE{bymonth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"bymonth"}) 8 50 58
1310 8 foreach my $BYMONTH (split ',', $RRULE{bymonth}) {
1311 9 ▶ unless ($BYMONTH =~ /^\d+L?$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($BYMONTH =~ /^\d+L?$/) 0 9 9
1312 0 confess "$uid: Invalid recurrence BYMONTH ($BYMONTH, $RRULE{bymonth})";
1313 }
1314  
1315 9 push @{$Recurrence{byMonth}}, "$BYMONTH";
1316 }
1317 }
1318  
1319 58 ▶ if (exists $RRULE{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"count"}) 16 42 58
1320 16 ▶ if (exists $RRULE{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"until"}) 0 16 16
1321 #confess "$uid: Recurrence COUNT and UNTIL cannot both be set";
1322 # seen in the wild: PRODID:-//dmfs.org//mimedir.icalendar//EN
1323 0 delete $RRULE{until};
1324 }
1325  
1326 16 ▶ unless ($RRULE{count} =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RRULE{"count"} =~ /^\d+$/) 0 16 16
1327 0 confess "$uid: Invalid recurrence COUNT ($RRULE{count})";
1328 }
1329  
1330 16 $Recurrence{count} = int $RRULE{count};
1331 }
1332  
1333 58 ▶ if (exists $RRULE{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"until"}) 6 52 58
1334 # rfc5545 3.3.10 - UNTIL must be in DTSTART timezone, but both
1335 # google and iCloud store it in Z, so we will too as per rfc2445.
1336 6 my ($Until, $IsAllDay) = $Self->_makeDateObj($RRULE{until}, $StartTimeZone, $StartTimeZone);
1337 6 $Recurrence{until} = $Until->iso8601();
1338 }
1339  
1340 # }}}
1341  
1342 # parse generic recurrence properties {{{
1343  
1344 58 foreach my $Property (keys %RecurrenceProperties) {
1345 406 ▶ if (defined $RRULE{$Property}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $RRULE{$Property}) 15 391 406
1346 15 foreach my $Value (split ',', $RRULE{$Property}) {
1347 my ($Valid, $Min) = $RecurrenceProperties{$Property}{signed}
1348 28 ▶ ? ('[-+]?[1-9]\d*', ($RecurrenceProperties{$Property}{max} * -1))
Branch: 1 branch
BranchTrueFalseTotal
$RecurrenceProperties{$Property}{'signed'} ? : 16 12 28
1349 : ('\d+', 0);
1350  
1351 28 ▶ unless ($Value =~ /^$Valid$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value =~ /^$Valid$/) 0 28 28
1352 0 confess "$uid: Invalid recurrence $Property ($Value)";
1353 }
1354  
1355 28 ▶ unless (($Value >= $Min) and ($Value <= $RecurrenceProperties{$Property}{max})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}) 0 28 28
Condition33%1/3
$Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}
!ll&&!rl&&r
0028
MC/DC0%0/2
$Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}
$Value >= $Min $Value <= $RecurrenceProperties{$Property}{"max"}
Truth table33%1/3
A and B
A= $Value >= $MinB= $Value <= $RecurrenceProperties{$Property}{"max"}
ABresult
0X0
100
111
1356 0 confess "$uid: Recurrence $Property is out of range ($Value)";
1357 }
1358  
1359 28 push @{$Recurrence{$RecurrenceProperties{$Property}{name}}}, int $Value;
1360 }
1361 }
1362 }
1363  
1364 # }}}
1365 58 1;
1366 };
1367 60 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 58 60
1368 2 %Recurrence = ();
1369 2 $Self->_error($uid, 'RRULE', $@);
1370 }
1371 }
1372  
1373 426 my %Overrides;
1374 426 ▶ if (exists $VEvent->{properties}{exdate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VEvent->{"properties"}{"exdate"}) 16 410 426
1375 16 foreach my $Item (@{$VEvent->{properties}{exdate}}) {
1376 17 foreach my $Date ($Self->_getDateObjMulti($Calendar, $Item, $StartTimeZone)) {
1377 18 $Overrides{$Date->iso8601()} = { excluded => $JSON::true }; # 4.3.3
1378 }
1379 }
1380 }
1381  
1382 426 ▶ if ($VEvent->{properties}{rdate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VEvent->{"properties"}{"rdate"}) 16 410 426
1383 # rdate = "RDATE" rdtparam ":" rdtval *("," rdtval) CRLF
1384 16 foreach my $Item (@{$VEvent->{properties}{rdate}}) {
1385 # a PERIOD's start is the key and its length the patch's
1386 # duration (jscalendar-icalendar-29 2.3.33)
1387 18 ▶ if (lc($Item->{params}{value}[0] || '') eq 'period') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($Item->{"params"}{"value"}[0] || "") eq "period") 6 12 18
Condition100%2/2
$Item->{'params'}{'value'}[0] || ''
l!l
810
MC/DC100%1/1
$Item->{'params'}{'value'}[0] || ''
$Item->{'params'}{'value'}[0]
Truth table100%2/2
A
A= $Item->{'params'}{'value'}[0]
Aresult
11
00
1388 6 my $TimeZone = $Self->_getTimeZone($Calendar, $Item);
1389 6 foreach my $Period (split /,/, $Item->{value}) {
1390 7 my ($From, $To) = split m{/}, $Period, 2;
1391 7 ▶ my ($Date) = eval { $Self->_makeDateObj($From, $TimeZone, $StartTimeZone) } or next;
Branch: 1 branch
BranchTrueFalseTotal
my($Date) = eval { do { $Self->_makeDateObj($From, $TimeZone, $StartTimeZone) } } or next 7 0 7
1392 7 my $Length;
1393 7 ▶ if (defined $To and $To =~ /^[+-]?P/i) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $To and $To =~ /^[+-]?P/i) { } 2 5 7
elsif (defined $To) { } 5 0 5
Condition66%2/3
defined $To and $To =~ /^[+-]?P/i
!ll&&!rl&&r
052
MC/DC50%1/2
defined $To and $To =~ /^[+-]?P/i
defined $To $To =~ /^[+-]?P/i
Truth table66%2/3
A and B
A= defined $ToB= $To =~ /^[+-]?P/i
ABresult
0X0
100
111
1394 2 $Length = eval { DateTime::Format::ICal->parse_duration(uc $To) };
1395 }
1396 elsif (defined $To) {
1397 5 my ($Until) = eval { $Self->_makeDateObj($To, $TimeZone, $StartTimeZone) };
1398 5 ▶ $Length = $Until->subtract_datetime($Date) if $Until;
Branch: 1 branch
BranchTrueFalseTotal
if $Until 5 0 5
1399 }
1400 7 ▶ $Overrides{$Date->iso8601()} = ($Length && !$Length->is_negative)
Branch: 1 branch
BranchTrueFalseTotal
$Length && !$Length->is_negative ? : 7 0 7
Condition33%1/3
$Length and not $Length->is_negative
!ll&&!rl&&r
007
MC/DC0%0/2
$Length and not $Length->is_negative
$Length not $Length->is_negative
Truth table33%1/3
A and not(B)
A= $LengthB= not $Length->is_negative
ABresult
0X0
100
111
1401 ? { duration => $Self->_make_duration($Length) } : {};
1402 }
1403 6 next;
1404 }
1405 12 foreach my $Date ($Self->_getDateObjMulti($Calendar, $Item, $StartTimeZone)) {
1406 12 $Overrides{$Date->iso8601()} = {};
1407 }
1408 }
1409 }
1410  
1411 # parse alarms {{{
1412  
1413 426 my %Alerts;
1414 426 ▶ foreach my $VAlarm (@{$VEvent->{objects} || []}) {
Condition100%2/2
$VEvent->{'objects'} || []
l!l
71355
MC/DC100%1/1
$VEvent->{'objects'} || []
$VEvent->{'objects'}
Truth table100%2/2
A
A= $VEvent->{'objects'}
Aresult
11
00
1415 111 ▶ next unless lc $VAlarm->{type} eq 'valarm';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $VAlarm->{"type"} eq "valarm" 12 99 111
1416 # a bad alarm drops only itself (see errors())
1417 99 my $alarmuid;
1418 99 my $ok = eval {
1419  
1420 my %AlarmProperties
1421 421 = map { $_ => $VAlarm->{properties}{$_}[0] }
1422 99 keys %{$VAlarm->{properties}};
1423  
1424 $alarmuid = $AlarmProperties{uid}{value}
1425 || $AlarmProperties{'x-wr-alarmuid'}{value}
1426 99 ▶ || _hexkey($VAlarm, $uid) . '-alarmauto';
Condition100%5/5
$AlarmProperties{'uid'}{'value'} || $AlarmProperties{'x-wr-alarmuid'}{'value'} || _hexkey($VAlarm, $uid) . '-alarmauto'
l!l
909
$AlarmProperties{"uid"}{"value"} or $AlarmProperties{"x-wr-alarmuid"}{"value"}
l!l&&r!l&&!r
8829
MC/DC100%2/2
$AlarmProperties{'uid'}{'value'} || $AlarmProperties{'x-wr-alarmuid'}{'value'} || _hexkey($VAlarm, $uid) . '-alarmauto'
$AlarmProperties{"uid"}{"value"} $AlarmProperties{"x-wr-alarmuid"}{"value"}
Truth table100%3/3
A or B
A= $AlarmProperties{"uid"}{"value"}B= $AlarmProperties{"x-wr-alarmuid"}{"value"}
ABresult
1X1
011
000
1427  
1428 99 my %Alert;
1429 99 $Alert{'@type'} = 'Alert';
1430  
1431 # ACTION is required (RFC 5545 3.6.6)
1432 99 ▶ my $AlarmAction = lc($AlarmProperties{action}{value} // die "VALARM without ACTION\n");
Condition100%2/2
$AlarmProperties{"action"}{"value"} // die("VALARM without ACTION\n")
l!l
981
MC/DC100%1/1
$AlarmProperties{"action"}{"value"} // die("VALARM without ACTION\n")
$AlarmProperties{"action"}{"value"}
Truth table100%2/2
A
A= $AlarmProperties{"action"}{"value"}
Aresult
11
00
1433 98 ▶ return 1 unless $AlarmAction;
Branch: 1 branch
BranchTrueFalseTotal
unless $AlarmAction 0 98 98
1434  
1435 98 ▶ if ($AlarmAction eq 'display' || $AlarmAction eq 'audio') {
Branch: 3 branches
BranchTrueFalseTotal
if ($AlarmAction eq 'display' or $AlarmAction eq 'audio') { } 88 10 98
elsif ($AlarmAction eq 'email') { } 8 2 10
elsif ($AlarmAction eq 'none') { } 2 0 2
Condition100%3/3
$AlarmAction eq "display" or $AlarmAction eq "audio"
l!l&&r!l&&!r
85310
MC/DC100%2/2
$AlarmAction eq "display" or $AlarmAction eq "audio"
$AlarmAction eq "display" $AlarmAction eq "audio"
Truth table100%3/3
A or B
A= $AlarmAction eq "display"B= $AlarmAction eq "audio"
ABresult
1X1
011
000
1436 88 $Alert{action} = 'display';
1437 }
1438 elsif ($AlarmAction eq 'email') {
1439 8 $Alert{action} = 'email';
1440 }
1441 elsif ($AlarmAction eq 'none') {
1442 2 return 1;
1443 }
1444 else {
1445 0 die "unknown VALARM ACTION $AlarmAction\n";
1446 }
1447  
1448 96 ▶ if ($AlarmProperties{acknowledged}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AlarmProperties{"acknowledged"}) 16 80 96
1449 16 my $date = $Self->_getDateObj($Calendar, $AlarmProperties{acknowledged}, 'UTC');
1450 16 $Alert{acknowledged} = $date->iso8601() . 'Z';
1451 }
1452  
1453 my $Trigger = $AlarmProperties{trigger}{value}
1454 96 ▶ || return 1;
Condition50%1/2
$AlarmProperties{'trigger'}{'value'} || (return 1)
l!l
960
MC/DC0%0/1
$AlarmProperties{'trigger'}{'value'} || (return 1)
$AlarmProperties{'trigger'}{'value'}
Truth table50%1/2
A
A= $AlarmProperties{'trigger'}{'value'}
Aresult
11
00
1455  
1456 96 ▶ my $Related = (lc ($AlarmProperties{trigger}{params}{related}[0] || '') eq 'end')
Branch: 1 branch
BranchTrueFalseTotal
lc($AlarmProperties{'trigger'}{'params'}{'related'}[0] || '') eq 'end' ? : 18 78 96
Condition100%2/2
$AlarmProperties{'trigger'}{'params'}{'related'}[0] || ''
l!l
2076
MC/DC100%1/1
$AlarmProperties{'trigger'}{'params'}{'related'}[0] || ''
$AlarmProperties{'trigger'}{'params'}{'related'}[0]
Truth table100%2/2
A
A= $AlarmProperties{'trigger'}{'params'}{'related'}[0]
Aresult
11
00
1457 ? 'end'
1458 : 'start';
1459  
1460 96 ▶ if ($Trigger =~ m/^[+-]?P/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Trigger =~ /^[+-]?P/i) { } 80 16 96
1461 80 ▶ my $Duration = eval { DateTime::Format::ICal->parse_duration(uc $Trigger) }
Condition50%1/2
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } } || (return 1)
l!l
800
MC/DC0%0/1
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } } || (return 1)
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } }
Truth table50%1/2
A
A= eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } }
Aresult
11
00
1462 || return 1;
1463  
1464 80 my ($IsNeg, $OffsetStr);
1465 80 ▶ if ($Duration->is_negative()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Duration->is_negative) 66 14 80
1466 66 $Duration = $Duration->inverse();
1467 66 $IsNeg = 1;
1468 }
1469 # jscalendarbis-22 3.5.1: on a Task, "end" MUST NOT be used
1470 # without a due. RFC 5545 3.8.6.3 puts such a VTODO's end at
1471 # DTSTART + DURATION, so say the same instant relative to start.
1472 80 ▶ if ($is_task and $Related eq 'end' and not $Properties{due}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task and $Related eq "end" and not $Properties{"due"}{"value"}) 2 78 80
Condition83%5/6
$is_task and $Related eq "end" and not $Properties{"due"}{"value"}
!ll&&!rl&&r
7352
$is_task and $Related eq "end"
!ll&&!rl&&r
7307
MC/DC66%2/3
$is_task and $Related eq "end" and not $Properties{"due"}{"value"}
$is_task $Related eq "end" not $Properties{"due"}{"value"}
Truth table75%3/4
A and B and not(C)
A= $is_taskB= $Related eq "end"C= not $Properties{"due"}{"value"}
ABCresult
0XX0
10X0
1100
1111
1473 2 my $Span = $End->subtract_datetime($Start);
1474 2 ▶ $Duration = $IsNeg ? $Span->clone->subtract_duration($Duration)
Branch: 1 branch
BranchTrueFalseTotal
$IsNeg ? : 2 0 2
1475 : $Span->clone->add_duration($Duration);
1476 2 $IsNeg = 0;
1477 2 ▶ if ($Duration->is_negative()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Duration->is_negative) 1 1 2
1478 1 $Duration = $Duration->inverse();
1479 1 $IsNeg = 1;
1480 }
1481 2 $Related = 'start';
1482 }
1483 80 ▶ $OffsetStr = ($IsNeg ? '-' : '') . $Self->_make_duration($Duration);
Branch: 1 branch
BranchTrueFalseTotal
$IsNeg ? : 65 15 80
1484 $Alert{trigger} = {
1485 80 '@type' => 'OffsetTrigger',
1486 'offset' => $OffsetStr,
1487 'relativeTo' => $Related,
1488 };
1489 }
1490 else {
1491 # Absolute trigger (VALUE=DATE-TIME)
1492 16 my $AlertDate = $Self->_getDateObj($Calendar, $AlarmProperties{trigger}, 'UTC');
1493 $Alert{trigger} = {
1494 16 '@type' => 'AbsoluteTrigger',
1495 'when' => $AlertDate->iso8601() . 'Z',
1496 };
1497 }
1498  
1499 96 $Alerts{$alarmuid} = \%Alert;
1500 96 1;
1501 };
1502 99 ▶ $Self->_error($uid, 'VALARM', $@, $alarmuid) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 98 99
1503 }
1504  
1505 # }}}
1506  
1507 # parse attendees {{{
1508  
1509 426 my %Participants;
1510 my %AddrKeys;
1511 426 ▶ for my $VProp (@{$VEvent->{properties}{organizer} || []},
Condition100%2/2
$VEvent->{'properties'}{'organizer'} || []
l!l
67359
MC/DC100%1/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1512 426 ▶ @{$VEvent->{properties}{attendee} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attendee'} || []
l!l
69357
MC/DC100%1/1
$VEvent->{'properties'}{'attendee'} || []
$VEvent->{'properties'}{'attendee'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attendee'}
Aresult
11
00
1513 194 ▶ my $jsid = _propJSID($VProp) // next;
Condition100%2/2
_propJSID($VProp) // (next)
l!l
39155
MC/DC100%1/1
_propJSID($VProp) // (next)
_propJSID($VProp)
Truth table100%2/2
A
A= _propJSID($VProp)
Aresult
11
00
1514 39 ▶ my $addr = $VProp->{value} // next;
Condition50%1/2
$VProp->{"value"} // (next)
l!l
390
MC/DC0%0/1
$VProp->{"value"} // (next)
$VProp->{"value"}
Truth table50%1/2
A
A= $VProp->{"value"}
Aresult
11
00
1515 39 $addr =~ s/^mailto://i;
1516 39 ▶ $AddrKeys{lc $addr} //= $jsid;
Condition66%2/3
$AddrKeys{lc $addr} //= $jsid
l!l&&r!l&&!r
7320
MC/DC0%0/2
$AddrKeys{lc $addr} //= $jsid
$AddrKeys{lc $addr} $jsid
Truth table66%2/3
A //= B
A= $AddrKeys{lc $addr}B= $jsid
ABresult
1X1
011
000
1517 }
1518 426 ▶ for my $VOrganizer (@{$VEvent->{properties}{organizer} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'organizer'} || []
l!l
67359
MC/DC100%1/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1519 67 $Self->_makeParticipant($Calendar, \%Participants, $VOrganizer, 'owner', \%AddrKeys);
1520 }
1521 426 ▶ for my $VAttendee (@{$VEvent->{properties}{attendee} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attendee'} || []
l!l
69357
MC/DC100%1/1
$VEvent->{'properties'}{'attendee'} || []
$VEvent->{'properties'}{'attendee'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attendee'}
Aresult
11
00
1522 127 $Self->_makeParticipant($Calendar, \%Participants, $VAttendee, 'attendee', \%AddrKeys);
1523 }
1524  
1525 # }}}
1526  
1527 # parse attachments {{{
1528  
1529 426 my %Links;
1530 426 ▶ foreach my $Attach (@{$VEvent->{properties}{attach} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attach'} || []
l!l
17409
MC/DC100%1/1
$VEvent->{'properties'}{'attach'} || []
$VEvent->{'properties'}{'attach'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attach'}
Aresult
11
00
1531 26 ▶ next unless $Attach->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $Attach->{"value"} 0 26 26
1532  
1533 26 my $uri;
1534 26 ▶ my $encoding = lc($Attach->{params}{encoding}[0] || '');
Condition100%2/2
$Attach->{'params'}{'encoding'}[0] || ''
l!l
125
MC/DC100%1/1
$Attach->{'params'}{'encoding'}[0] || ''
$Attach->{'params'}{'encoding'}[0]
Truth table100%2/2
A
A= $Attach->{'params'}{'encoding'}[0]
Aresult
11
00
1535 26 ▶ if ($encoding eq 'base64' || $encoding eq 'b') {
Branch: 2 branches
BranchTrueFalseTotal
if ($encoding eq 'base64' or $encoding eq 'b') { } 1 25 26
elsif (grep {$Attach->{'value'} =~ m[^$_://];} 'http', 'https', 'ftp', 'data') { } 23 2 25
Condition66%2/3
$encoding eq "base64" or $encoding eq "b"
l!l&&r!l&&!r
1025
MC/DC50%1/2
$encoding eq "base64" or $encoding eq "b"
$encoding eq "base64" $encoding eq "b"
Truth table66%2/3
A or B
A= $encoding eq "base64"B= $encoding eq "b"
ABresult
1X1
011
000
1536 # Binary ATTACH - convert to data: URI
1537 1 ▶ my $mime = $Attach->{params}{fmttype}[0] || 'application/octet-stream';
Condition50%1/2
$Attach->{'params'}{'fmttype'}[0] || 'application/octet-stream'
l!l
10
MC/DC0%0/1
$Attach->{'params'}{'fmttype'}[0] || 'application/octet-stream'
$Attach->{'params'}{'fmttype'}[0]
Truth table50%1/2
A
A= $Attach->{'params'}{'fmttype'}[0]
Aresult
11
00
1538 1 $uri = "data:$mime;base64," . $Attach->{value};
1539 }
1540 100 elsif (grep { $Attach->{value} =~ m{^$_://} } qw{http https ftp data}) {
1541 23 $uri = $Attach->{value};
1542 }
1543 else {
1544 2 next;
1545 }
1546  
1547 24 my $filename = $Attach->{params}{filename}[0];
1548 24 my $mime = $Attach->{params}{fmttype}[0];
1549 24 ▶ if (not defined $mime and $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mime and $filename) 1 23 24
Condition100%3/3
not defined $mime and $filename
!ll&&!rl&&r
8151
MC/DC100%2/2
not defined $mime and $filename
not defined $mime $filename
Truth table100%3/3
not(A) and B
A= not defined $mimeB= $filename
ABresult
0X0
100
111
1550 1 ▶ $MimeTypes ||= MIME::Types->new;
Condition33%1/3
$MimeTypes ||= "MIME::Types"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$MimeTypes ||= "MIME::Types"->new
$MimeTypes "MIME::Types"->new
Truth table33%1/3
A ||= B
A= $MimeTypesB= "MIME::Types"->new
ABresult
1X1
011
000
1551 1 my $MimeTypeObj = $MimeTypes->mimeTypeOf($filename);
1552 1 ▶ $mime = $MimeTypeObj->type() if $MimeTypeObj;
Branch: 1 branch
BranchTrueFalseTotal
if $MimeTypeObj 1 0 1
1553 }
1554  
1555 24 my $size = $Attach->{params}{size}[0];
1556  
1557 24 ▶ $Links{_propJSID($Attach) // sha1_hex(lc $uri)} = {
Branch: 3 branches
BranchTrueFalseTotal
defined $filename ? : 3 21 24
defined $mime ? : 9 15 24
defined $size && $size =~ /^\d+$/ ? : 6 18 24
Condition66%4/6
defined $size and $size =~ /^\d+$/
!ll&&!rl&&r
1806
_propJSID($Attach) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
12120
MC/DC50%1/2
defined $size and $size =~ /^\d+$/
defined $size $size =~ /^\d+$/
MC/DC0%0/2
_propJSID($Attach) // &sha1_hex(lc $uri)
_propJSID($Attach) &sha1_hex(lc $uri)
Truth table66%2/3
A and B
A= defined $sizeB= $size =~ /^\d+$/
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Attach)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1558 href => $uri,
1559 rel => 'enclosure',
1560 defined $filename ? (title => $filename) : (),
1561 defined $mime ? (contentType => $mime) : (),
1562 (defined $size && $size =~ /^\d+$/) ? (size => 0+$size) : (),
1563 };
1564 }
1565 # URL -> a link with rel "describedby", its title in LABEL
1566 # (jscalendar-icalendar 2.3.46)
1567 426 ▶ foreach my $URL (@{$VEvent->{properties}{url} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'url'} || []
l!l
9417
MC/DC100%1/1
$VEvent->{'properties'}{'url'} || []
$VEvent->{'properties'}{'url'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'url'}
Aresult
11
00
1568 9 my $uri = $URL->{value};
1569 9 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 9 9
1570 9 ▶ $Links{_propJSID($URL) // sha1_hex(lc $uri)} = {
Condition66%2/3
_propJSID($URL) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
630
MC/DC0%0/2
_propJSID($URL) // &sha1_hex(lc $uri)
_propJSID($URL) &sha1_hex(lc $uri)
Truth table66%2/3
A // B
A= _propJSID($URL)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1571 href => $uri,
1572 rel => 'describedby',
1573 _linkTitle($URL, 'label'),
1574 };
1575 }
1576 # IMAGE -> a link with rel "icon", its title in FILENAME
1577 # (jscalendar-icalendar 2.3.22; LABEL, which this module used to
1578 # write, is still read)
1579 426 ▶ foreach my $Image (@{$VEvent->{properties}{image} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'image'} || []
l!l
4422
MC/DC100%1/1
$VEvent->{'properties'}{'image'} || []
$VEvent->{'properties'}{'image'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'image'}
Aresult
11
00
1580 4 my $uri = $Image->{value};
1581 4 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 4 4
1582 4 my $size = $Image->{params}{size}[0];
1583 4 ▶ my @display = map { lc } grep { length } map { split /,/ } @{$Image->{params}{display} || []};
Condition50%1/2
$Image->{'params'}{'display'} || []
l!l
40
MC/DC0%0/1
$Image->{'params'}{'display'} || []
$Image->{'params'}{'display'}
Truth table50%1/2
A
A= $Image->{'params'}{'display'}
Aresult
11
00
1584 $Links{_propJSID($Image) // sha1_hex(lc $uri)} = {
1585 href => $uri,
1586 rel => 'icon',
1587 defined $Image->{params}{fmttype}[0] ? (contentType => $Image->{params}{fmttype}[0]) : (),
1588 (defined $size && $size =~ /^\d+$/) ? (size => 0+$size) : (),
1589 4 ▶ @display ? (display => { map { $_ => $JSON::true } @display }) : (),
Branch: 3 branches
BranchTrueFalseTotal
defined $Image->{'params'}{'fmttype'}[0] ? : 4 0 4
defined $size && $size =~ /^\d+$/ ? : 0 4 4
@display ? : 4 0 4
Condition50%3/6
defined $size and $size =~ /^\d+$/
!ll&&!rl&&r
400
_propJSID($Image) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
220
MC/DC0%0/2
defined $size and $size =~ /^\d+$/
defined $size $size =~ /^\d+$/
MC/DC0%0/2
_propJSID($Image) // &sha1_hex(lc $uri)
_propJSID($Image) &sha1_hex(lc $uri)
Truth table33%1/3
A and B
A= defined $sizeB= $size =~ /^\d+$/
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Image)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1590 _linkTitle($Image, 'filename', 'label'),
1591 };
1592 }
1593 # LINK with value type URI (jscalendar-icalendar 2.3.24): LINKREL is
1594 # the rel, LABEL the title; any other value type does not convert
1595 426 ▶ foreach my $Link (@{$VEvent->{properties}{link} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'link'} || []
l!l
5421
MC/DC100%1/1
$VEvent->{'properties'}{'link'} || []
$VEvent->{'properties'}{'link'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'link'}
Aresult
11
00
1596 8 my $uri = $Link->{value};
1597 8 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 8 8
1598 8 ▶ next unless lc($Link->{params}{value}[0] // 'uri') eq 'uri';
Branch: 1 branch
BranchTrueFalseTotal
unless lc($Link->{"params"}{"value"}[0] // "uri") eq "uri" 1 7 8
Condition50%1/2
$Link->{"params"}{"value"}[0] // "uri"
l!l
80
MC/DC0%0/1
$Link->{"params"}{"value"}[0] // "uri"
$Link->{"params"}{"value"}[0]
Truth table50%1/2
A
A= $Link->{"params"}{"value"}[0]
Aresult
11
00
1599 7 my $rel = $Link->{params}{linkrel}[0];
1600 $Links{_propJSID($Link) // sha1_hex(lc $uri)} = {
1601 href => $uri,
1602 defined $rel && length $rel ? (rel => $rel) : (),
1603 7 ▶ defined $Link->{params}{fmttype}[0] ? (contentType => $Link->{params}{fmttype}[0]) : (),
Branch: 2 branches
BranchTrueFalseTotal
defined $rel && length $rel ? : 7 0 7
defined $Link->{'params'}{'fmttype'}[0] ? : 1 6 7
Condition50%3/6
defined $rel and length $rel
!ll&&!rl&&r
007
_propJSID($Link) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
430
MC/DC0%0/2
defined $rel and length $rel
defined $rel length $rel
MC/DC0%0/2
_propJSID($Link) // &sha1_hex(lc $uri)
_propJSID($Link) &sha1_hex(lc $uri)
Truth table33%1/3
A and B
A= defined $relB= length $rel
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Link)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1604 _linkTitle($Link, 'label'),
1605 };
1606 }
1607  
1608 # }}}
1609  
1610 # parse CONFERENCE -> virtualLocations {{{
1611  
1612 426 my %VirtualLocations;
1613 426 ▶ foreach my $Conference (@{$VEvent->{properties}{conference} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'conference'} || []
l!l
9417
MC/DC100%1/1
$VEvent->{'properties'}{'conference'} || []
$VEvent->{'properties'}{'conference'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'conference'}
Aresult
11
00
1614 14 ▶ next unless $Conference->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $Conference->{"value"} 0 14 14
1615 14 ▶ my $id = $Conference->{params}{'x-jmap-id'}[0] || sha1_hex($Conference->{value});
Condition66%2/3
$Conference->{'params'}{'x-jmap-id'}[0] || &sha1_hex($Conference->{'value'})
l!l&&r!l&&!r
1220
MC/DC0%0/2
$Conference->{'params'}{'x-jmap-id'}[0] || &sha1_hex($Conference->{'value'})
$Conference->{'params'}{'x-jmap-id'}[0] &sha1_hex($Conference->{'value'})
Truth table66%2/3
A || B
A= $Conference->{'params'}{'x-jmap-id'}[0]B= &sha1_hex($Conference->{'value'})
ABresult
1X1
011
000
1616 14 my %vloc = ('@type' => 'VirtualLocation', uri => $Conference->{value});
1617 14 ▶ if ($Conference->{params}{label}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Conference->{"params"}{"label"}) 12 2 14
1618 12 $vloc{name} = $Conference->{params}{label}[0];
1619 }
1620 14 ▶ if ($Conference->{params}{feature}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Conference->{"params"}{"feature"}) 12 2 14
1621 12 my @features = map { lc $_ } map { split /,/ } @{$Conference->{params}{feature}};
1622 12 $vloc{features} = { map { $_ => $JSON::true } @features };
1623 }
1624 14 $VirtualLocations{$id} = \%vloc;
1625 }
1626  
1627 # }}}
1628  
1629 # Parse keywords {{{
1630  
1631 426 my %keywords;
1632 426 ▶ foreach my $Categories (@{$VEvent->{properties}{categories} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'categories'} || []
l!l
7419
MC/DC100%1/1
$VEvent->{'properties'}{'categories'} || []
$VEvent->{'properties'}{'categories'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'categories'}
Aresult
11
00
1633 10 my $val = $Categories->{value};
1634 10 $keywords{$_} = $JSON::true for split ',', $val;
1635 }
1636 426 delete $keywords{''}; # just in case it was created by leading or trailing ,
1637  
1638 # }}}
1639  
1640 # Parse relations {{{
1641  
1642 426 my %relations;
1643 426 ▶ foreach my $Relation (@{$VEvent->{properties}{'related-to'} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'related-to'} || []
l!l
21405
MC/DC100%1/1
$VEvent->{'properties'}{'related-to'} || []
$VEvent->{'properties'}{'related-to'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'related-to'}
Aresult
11
00
1644 38 ▶ my $reltype = $Relation->{params}{reltype}[0] || 'parent';
Condition100%2/2
$Relation->{'params'}{'reltype'}[0] || 'parent'
l!l
1721
MC/DC100%1/1
$Relation->{'params'}{'reltype'}[0] || 'parent'
$Relation->{'params'}{'reltype'}[0]
Truth table100%2/2
A
A= $Relation->{'params'}{'reltype'}[0]
Aresult
11
00
1645 38 ▶ $reltype = lc $reltype if grep { $_ eq lc $reltype } qw(first next parent child);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq lc $reltype;} "first", "next", "parent", "child" 34 4 38
1646 38 $relations{$Relation->{value}}{'@type'} = 'Relation';
1647 38 $relations{$Relation->{value}}{relation}{$reltype} = $JSON::true;
1648 }
1649  
1650 # }}}
1651  
1652 426 my %Event = ();
1653  
1654 # ==============================================================
1655 # 4.1 Metadata
1656  
1657 # 4.1.1 @type (JSCalendar bis uses capitalized names)
1658 426 ▶ $Event{'@type'} = $is_task ? 'Task' : 'Event';
Branch: 1 branch
BranchTrueFalseTotal
$is_task ? : 12 414 426
1659  
1660 # 4.1.2 uid
1661 426 $Event{uid} = "$uid";
1662  
1663 # 4.1.3 relatedTo
1664 426 ▶ $Event{relatedTo} = \%relations if %relations;
Branch: 1 branch
BranchTrueFalseTotal
if %relations 21 405 426
1665  
1666 # 4.1.4 prodId
1667 426 ▶ $Event{prodId} = $prodid if defined $prodid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prodid 426 0 426
1668  
1669 # 4.1.5 created
1670 426 ▶ if ($Properties{created}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"created"}{"value"}) 111 315 426
1671 # UTC item
1672 111 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{created}, 'UTC') };
1673 111 ▶ $Event{created} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 111 0 111
1674 }
1675  
1676 # 4.1.6 updated
1677 426 ▶ if ($Properties{dtstamp}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"dtstamp"}{"value"}) 426 0 426
1678 # UTC item
1679 426 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{dtstamp}, 'UTC') };
1680 426 ▶ $Event{updated} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 426 0 426
1681 }
1682 426 ▶ if (not $Event{updated} and $Properties{'last-modified'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Event{"updated"} and $Properties{"last-modified"}{"value"}) 0 426 426
Condition33%1/3
not $Event{"updated"} and $Properties{"last-modified"}{"value"}
!ll&&!rl&&r
42600
MC/DC0%0/2
not $Event{"updated"} and $Properties{"last-modified"}{"value"}
not $Event{"updated"} $Properties{"last-modified"}{"value"}
Truth table33%1/3
not(A) and B
A= not $Event{"updated"}B= $Properties{"last-modified"}{"value"}
ABresult
0X0
100
111
1683 # UTC item
1684 0 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{'last-modified'}, 'UTC') };
1685 0 ▶ $Event{updated} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 0 0 0
1686 }
1687 426 ▶ $Event{updated} ||= DateTime->now->iso8601();
Condition33%1/3
$Event{"updated"} ||= "DateTime"->now->iso8601
l!l&&r!l&&!r
42600
MC/DC0%0/2
$Event{"updated"} ||= "DateTime"->now->iso8601
$Event{"updated"} "DateTime"->now->iso8601
Truth table33%1/3
A ||= B
A= $Event{"updated"}B= "DateTime"->now->iso8601
ABresult
1X1
011
000
1688  
1689 # 4.1.7 sequence
1690 # (a value that is not an integer is ignored; it used to die, when
1691 # the module made every warning fatal)
1692 426 my $sequence = _intValue($Properties{sequence}{value});
1693 426 ▶ $Event{sequence} = $sequence if defined $sequence;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sequence 272 154 426
1694  
1695 # 4.1.8 method
1696 426 ▶ $Event{method} = $method if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 2 424 426
1697  
1698 # ==============================================================
1699 # 4.2 What and where
1700  
1701 # 4.2.1 title
1702 $Event{title} = $Properties{summary}{value}
1703 426 ▶ if ($Properties{summary} and defined $Properties{summary}{value});
Branch: 1 branch
BranchTrueFalseTotal
if $Properties{"summary"} and defined $Properties{"summary"}{"value"} 234 192 426
Condition66%2/3
$Properties{"summary"} and defined $Properties{"summary"}{"value"}
!ll&&!rl&&r
0192234
MC/DC50%1/2
$Properties{"summary"} and defined $Properties{"summary"}{"value"}
$Properties{"summary"} defined $Properties{"summary"}{"value"}
Truth table66%2/3
A and B
A= $Properties{"summary"}B= defined $Properties{"summary"}{"value"}
ABresult
0X0
100
111
1704  
1705 # 4.2.2 description
1706 # STYLED-DESCRIPTION overrides DESCRIPTION if present
1707 426 ▶ if ($Properties{'styled-description'}{value}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Properties{'styled-description'}{'value'}) { } 3 423 426
elsif (@description) { } 88 335 423
1708 3 $Event{description} = $Properties{'styled-description'}{value};
1709 3 ▶ $Event{descriptionContentType} = $Properties{'styled-description'}{params}{fmttype}[0] // 'text/html';
Condition50%1/2
$Properties{"styled-description"}{"params"}{"fmttype"}[0] // "text/html"
l!l
30
MC/DC0%0/1
$Properties{"styled-description"}{"params"}{"fmttype"}[0] // "text/html"
$Properties{"styled-description"}{"params"}{"fmttype"}[0]
Truth table50%1/2
A
A= $Properties{"styled-description"}{"params"}{"fmttype"}[0]
Aresult
11
00
1710 }
1711 elsif (@description) {
1712 88 $Event{description} = join("\n", @description);
1713 }
1714  
1715 # 4.2.4 locations
1716 426 ▶ if ($Properties{location}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"location"}{"value"}) 34 392 426
1717 34 $Event{locations}{location} = { '@type' => 'Location', name => $Properties{location}{value} };
1718 }
1719 # X-APPLE-STRUCTURED-LOCATION -> location with coordinates, name, description
1720 # Check for Apple structured locations first; if present, skip plain GEO
1721 426 ▶ my $has_apple_location = scalar @{$VEvent->{properties}{'x-apple-structured-location'} || []};
Condition100%2/2
$VEvent->{'properties'}{'x-apple-structured-location'} || []
l!l
5421
MC/DC100%1/1
$VEvent->{'properties'}{'x-apple-structured-location'} || []
$VEvent->{'properties'}{'x-apple-structured-location'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'x-apple-structured-location'}
Aresult
11
00
1722  
1723 # GEO -> separate location with coordinates (only if no Apple structured location)
1724 426 ▶ if (!$has_apple_location && $Properties{geo}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_apple_location and $Properties{"geo"}{"value"}) 9 417 426
Condition100%3/3
not $has_apple_location and $Properties{"geo"}{"value"}
!ll&&!rl&&r
54129
MC/DC100%2/2
not $has_apple_location and $Properties{"geo"}{"value"}
not $has_apple_location $Properties{"geo"}{"value"}
Truth table100%3/3
not(A) and B
A= not $has_apple_locationB= $Properties{"geo"}{"value"}
ABresult
0X0
100
111
1725 9 my ($lat, $lon) = split /;/, $Properties{geo}{value};
1726 9 ▶ if (defined $lat && defined $lon) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lat and defined $lon) 9 0 9
Condition33%1/3
defined $lat and defined $lon
!ll&&!rl&&r
009
MC/DC0%0/2
defined $lat and defined $lon
defined $lat defined $lon
Truth table33%1/3
A and B
A= defined $latB= defined $lon
ABresult
0X0
100
111
1727 9 my $coords = "geo:$lat,$lon";
1728 9 ▶ my $locid = $Event{locations} ? 'geo' : 'location';
Branch: 1 branch
BranchTrueFalseTotal
$Event{'locations'} ? : 2 7 9
1729 9 $Event{locations}{$locid} = { '@type' => 'Location', coordinates => $coords };
1730 }
1731 }
1732  
1733 426 ▶ for my $ASL (@{$VEvent->{properties}{'x-apple-structured-location'} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'x-apple-structured-location'} || []
l!l
5421
MC/DC100%1/1
$VEvent->{'properties'}{'x-apple-structured-location'} || []
$VEvent->{'properties'}{'x-apple-structured-location'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'x-apple-structured-location'}
Aresult
11
00
1734 5 ▶ next unless $ASL->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $ASL->{"value"} 0 5 5
1735 5 my %loc = ('@type' => 'Location');
1736 5 ▶ if ($ASL->{value} =~ m{^geo:([-\d.]+),([-\d.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ASL->{"value"} =~ /^geo:([-\d.]+),([-\d.]+)/) 5 0 5
1737 5 $loc{coordinates} = $ASL->{value};
1738 }
1739 5 my $title = $ASL->{params}{'x-title'}[0];
1740 5 ▶ $loc{name} = $title if defined $title && $title ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $title and $title ne "" 5 0 5
Condition33%1/3
defined $title and $title ne ""
!ll&&!rl&&r
005
MC/DC0%0/2
defined $title and $title ne ""
defined $title $title ne ""
Truth table33%1/3
A and B
A= defined $titleB= $title ne ""
ABresult
0X0
100
111
1741 5 my $address = $ASL->{params}{'x-address'}[0];
1742 5 ▶ $loc{description} = $address if defined $address && $address ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $address and $address ne "" 0 5 5
Condition33%1/3
defined $address and $address ne ""
!ll&&!rl&&r
500
MC/DC0%0/2
defined $address and $address ne ""
defined $address $address ne ""
Truth table33%1/3
A and B
A= defined $addressB= $address ne ""
ABresult
0X0
100
111
1743 5 ▶ if (keys %loc > 1) { # more than just @type
Branch: 1 branch
BranchTrueFalseTotal
if (keys %loc > 1) 5 0 5
1744 5 ▶ my $locid = sha1_hex($ASL->{value} || 'apple-location');
Condition50%1/2
$ASL->{'value'} || 'apple-location'
l!l
50
MC/DC0%0/1
$ASL->{'value'} || 'apple-location'
$ASL->{'value'}
Truth table50%1/2
A
A= $ASL->{'value'}
Aresult
11
00
1745 5 $Event{locations}{$locid} = \%loc;
1746 }
1747 }
1748  
1749 # 4.2.5 virtualLocations
1750 426 ▶ $Event{virtualLocations} = \%VirtualLocations if %VirtualLocations;
Branch: 1 branch
BranchTrueFalseTotal
if %VirtualLocations 9 417 426
1751  
1752 # 4.2.6 links
1753 426 ▶ $Event{links} = \%Links if %Links;
Branch: 1 branch
BranchTrueFalseTotal
if %Links 22 404 426
1754  
1755 # 4.2.7 locale
1756 426 my $language;
1757 426 ▶ if ($Properties{description} and $Properties{description}{params}{language}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"description"} and $Properties{"description"}{"params"}{"language"}) 23 403 426
Condition66%2/3
$Properties{"description"} and $Properties{"description"}{"params"}{"language"}
!ll&&!rl&&r
040323
MC/DC50%1/2
$Properties{"description"} and $Properties{"description"}{"params"}{"language"}
$Properties{"description"} $Properties{"description"}{"params"}{"language"}
Truth table66%2/3
A and B
A= $Properties{"description"}B= $Properties{"description"}{"params"}{"language"}
ABresult
0X0
100
111
1758 23 $language = $Properties{description}{params}{language}[0];
1759 }
1760 426 ▶ if ($Properties{summary} and $Properties{summary}{params}{language}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}) 47 379 426
Condition66%2/3
$Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}
!ll&&!rl&&r
037947
MC/DC50%1/2
$Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}
$Properties{"summary"} $Properties{"summary"}{"params"}{"language"}
Truth table66%2/3
A and B
A= $Properties{"summary"}B= $Properties{"summary"}{"params"}{"language"}
ABresult
0X0
100
111
1761 47 $language = $Properties{summary}{params}{language}[0];
1762 }
1763 426 ▶ $Event{locale} = $language if $language;
Branch: 1 branch
BranchTrueFalseTotal
if $language 47 379 426
1764  
1765 # 4.2.8 keywords
1766 426 ▶ $Event{keywords} = \%keywords if %keywords;
Branch: 1 branch
BranchTrueFalseTotal
if %keywords 7 419 426
1767  
1768 # 4.2.9 categories is not supported
1769  
1770 # 4.2.10 color
1771 # (one the module cannot read is dropped: it used to die, taking the
1772 # whole calendar with it)
1773 426 ▶ if ($Properties{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"color"}) 14 412 426
1774 14 my $color = eval { _fixColor($Properties{color}{value}) };
1775 14 ▶ $Event{color} = $color if defined $color;
Branch: 1 branch
BranchTrueFalseTotal
if defined $color 12 2 14
1776 }
1777  
1778 # ==============================================================
1779 # 4.3 Recurrence properties
1780  
1781 # 4.3.1 recurrenceRule (a singular object since jscalendarbis-15)
1782 426 ▶ if (%Recurrence) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Recurrence) 58 368 426
1783 58 $Recurrence{'@type'} = 'RecurrenceRule';
1784 58 $Event{recurrenceRule} = \%Recurrence;
1785 }
1786  
1787 # 4.3.2 recurrenceOverrides
1788 426 ▶ $Event{recurrenceOverrides} = \%Overrides if %Overrides;
Branch: 1 branch
BranchTrueFalseTotal
if %Overrides 23 403 426
1789  
1790 # ... special case for recurrence overrides when processing the child ...
1791 426 ▶ if ($Properties{'recurrence-id'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"recurrence-id"}{"value"}) 55 371 426
1792 # in our system it's always in the timezone of the event, but iCloud
1793 # returns it in UTC despite the event having a timezone. Super weird.
1794 # Anyway, we need to format it to the StartTimeZone of the parent
1795 # event if there is one, and we don't have that yet!
1796 55 $Event{_recurrenceObj} = $Self->_getDateObj($Calendar, $Properties{'recurrence-id'});
1797 }
1798  
1799 # ==============================================================
1800 # 4.4 Sharing and scheduling properties
1801  
1802 # 4.4.1 priority
1803 # default is 0, so a truth test is sufficient
1804 426 ▶ if (my $priority = _intValue($Properties{priority}{value})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $priority = _intValue($Properties{"priority"}{"value"})) 9 417 426
1805 9 $Event{priority} = $priority;
1806 }
1807  
1808 # 4.4.2 freeBusyStatus
1809 426 ▶ if ($Properties{transp}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"transp"}{"value"}) 287 139 426
1810 287 ▶ $Event{freeBusyStatus} = 'free' if lc($Properties{transp}{value}) eq 'transparent';
Branch: 1 branch
BranchTrueFalseTotal
if lc $Properties{"transp"}{"value"} eq "transparent" 103 184 287
1811 }
1812  
1813 # 4.4.3 privacy (from CLASS property)
1814 426 ▶ if ($Properties{class}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"class"}{"value"}) 12 414 426
1815 12 my $cls = lc($Properties{class}{value});
1816 12 ▶ if ($cls eq 'confidential') { $Event{privacy} = 'secret' }
Branch: 2 branches
BranchTrueFalseTotal
if ($cls eq 'confidential') { } 2 10 12
elsif ($cls ne 'public') { } 9 1 10
1817 # jscalendar-icalendar-29 2.3.7: any other value MUST be private
1818 9 elsif ($cls ne 'public') { $Event{privacy} = 'private' }
1819 }
1820  
1821 # 4.4.4 organizerCalendarAddress
1822 426 foreach my $partid (sort keys %Participants) { # later wins
1823 159 ▶ next unless $Participants{$partid}{roles}{owner};
Branch: 1 branch
BranchTrueFalseTotal
unless $Participants{$partid}{"roles"}{"owner"} 86 73 159
1824 73 $Event{organizerCalendarAddress} = $Participants{$partid}{calendarAddress};
1825 }
1826  
1827 # sentBy (jscalendarbis-22 3.4.5): the ORGANIZER's SENT-BY
1828 # (jscalendar-icalendar-29 2.3.29), which needs an organizer
1829 426 ▶ if ($Event{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Event{"organizerCalendarAddress"}) 67 359 426
1830 67 ▶ for my $VOrganizer (@{$VEvent->{properties}{organizer} || []}) {
Condition50%1/2
$VEvent->{'properties'}{'organizer'} || []
l!l
670
MC/DC0%0/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table50%1/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1831 67 ▶ my $SentBy = _sentByAddress($VOrganizer) // next;
Condition100%2/2
_sentByAddress($VOrganizer) // (next)
l!l
265
MC/DC100%1/1
_sentByAddress($VOrganizer) // (next)
_sentByAddress($VOrganizer)
Truth table100%2/2
A
A= _sentByAddress($VOrganizer)
Aresult
11
00
1832 2 $Event{sentBy} = $SentBy;
1833 2 last;
1834 }
1835 }
1836  
1837 # 4.4.5 participants
1838 426 ▶ $Event{participants} = \%Participants if %Participants;
Branch: 1 branch
BranchTrueFalseTotal
if %Participants 77 349 426
1839  
1840 # ==============================================================
1841 # 4.5 Alerts
1842  
1843 # 4.5.1 alerts
1844 426 ▶ $Event{alerts} = \%Alerts if %Alerts;
Branch: 1 branch
BranchTrueFalseTotal
if %Alerts 60 366 426
1845  
1846 # version (jscalendarbis)
1847 426 $Event{version} = '2.0';
1848  
1849 # 4.6.1 localisations is not supported
1850  
1851 # ==============================================================
1852 # 5.1 JSEvent specific properties
1853  
1854 # 5.1.1 start
1855 426 ▶ $Event{start} = $Start->iso8601() if ref($Start);
Branch: 1 branch
BranchTrueFalseTotal
if ref $Start 426 0 426
1856  
1857 # 5.1.2 timeZone: not set for a DATE or a floating time (it can no
1858 # longer be null, jscalendarbis-22 3.6.1, jscalendar-icalendar-29 2.1.5)
1859 426 ▶ $Event{timeZone} = $StartTimeZone if not $IsAllDay and defined $StartTimeZone and length $StartTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
if not $IsAllDay and defined $StartTimeZone and length $StartTimeZone 394 32 426
Condition83%5/6
not $IsAllDay and defined $StartTimeZone and length $StartTimeZone
!ll&&!rl&&r
320394
not $IsAllDay and defined $StartTimeZone
!ll&&!rl&&r
248394
MC/DC66%2/3
not $IsAllDay and defined $StartTimeZone and length $StartTimeZone
not $IsAllDay defined $StartTimeZone length $StartTimeZone
Truth table75%3/4
not(A) and B and C
A= not $IsAllDayB= defined $StartTimeZoneC= length $StartTimeZone
ABCresult
0XX0
10X0
1100
1111
1860  
1861 # endTimeZone (jscalendarbis): set if end timezone differs from start
1862 426 ▶ if (!$IsAllDay && $EndTimeZone && $StartTimeZone && $EndTimeZone ne $StartTimeZone) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone) 7 419 426
Condition88%8/9
not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone
!ll&&!rl&&r
323877
not $IsAllDay and $EndTimeZone and $StartTimeZone
!ll&&!rl&&r
320394
not $IsAllDay and $EndTimeZone
!ll&&!rl&&r
248394
MC/DC75%3/4
not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone
not $IsAllDay $EndTimeZone $StartTimeZone $EndTimeZone ne $StartTimeZone
Truth table80%4/5
not(A) and B and C and D
A= not $IsAllDayB= $EndTimeZoneC= $StartTimeZoneD= $EndTimeZone ne $StartTimeZone
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1863 7 $Event{endTimeZone} = $EndTimeZone;
1864 }
1865  
1866 # 5.1.3 duration
1867 426 my $duration = $Self->_make_duration($End->subtract_datetime($Start), $IsAllDay);
1868 426 ▶ $Event{duration} = $duration if $duration;
Branch: 1 branch
BranchTrueFalseTotal
if $duration 426 0 426
1869  
1870 # 5.1.4 showWithoutTime (RFC 8984)
1871 426 ▶ $Event{showWithoutTime} = $IsAllDay ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$IsAllDay ? : 24 402 426
1872 # SHOW-WITHOUT-TIME property (for DATE-TIME events shown as all-day)
1873 426 ▶ if (!$IsAllDay && $Properties{'show-without-time'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $Properties{"show-without-time"}{"value"}) 5 421 426
Condition100%3/3
not $IsAllDay and $Properties{"show-without-time"}{"value"}
!ll&&!rl&&r
243975
MC/DC100%2/2
not $IsAllDay and $Properties{"show-without-time"}{"value"}
not $IsAllDay $Properties{"show-without-time"}{"value"}
Truth table100%3/3
not(A) and B
A= not $IsAllDayB= $Properties{"show-without-time"}{"value"}
ABresult
0X0
100
111
1874 5 my $swt = lc($Properties{'show-without-time'}{value});
1875 5 ▶ $Event{showWithoutTime} = $JSON::true if $swt eq 'true' || $swt eq 'yes';
Branch: 1 branch
BranchTrueFalseTotal
if $swt eq "true" or $swt eq "yes" 5 0 5
Condition33%1/3
$swt eq "true" or $swt eq "yes"
l!l&&r!l&&!r
500
MC/DC0%0/2
$swt eq "true" or $swt eq "yes"
$swt eq "true" $swt eq "yes"
Truth table33%1/3
A or B
A= $swt eq "true"B= $swt eq "yes"
ABresult
1X1
011
000
1876 }
1877  
1878 # 5.1.5 status
1879 426 ▶ if ($Properties{status}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"status"}{"value"}) 12 414 426
1880 12 ▶ $Event{status} = lc($Properties{status}{value}) if lc($Properties{status}{value}) ne 'confirmed';
Branch: 1 branch
BranchTrueFalseTotal
if lc $Properties{"status"}{"value"} ne "confirmed" 12 0 12
1881 }
1882  
1883 # Task-specific properties (VTODO)
1884 426 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) 12 414 426
1885 12 ▶ if ($Properties{due}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"due"}{"value"}) 8 4 12
1886 8 my ($Due, $DueTz) = $Self->_getDateObj($Calendar, $Properties{due});
1887 8 $Event{due} = $Due->iso8601();
1888 }
1889 12 my $percent = _intValue($Properties{'percent-complete'}{value});
1890 12 ▶ $Event{percentComplete} = $percent if defined $percent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $percent 5 7 12
1891 12 ▶ if ($Properties{'estimated-duration'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"estimated-duration"}{"value"}) 1 11 12
1892 1 $Event{estimatedDuration} = uc $Properties{'estimated-duration'}{value};
1893 }
1894 12 ▶ if ($Properties{completed}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Properties{'completed'}{'value'}) { } 1 11 12
elsif (lc($Properties{'status'}{'value'} || '') eq 'in-process') { } 4 7 11
elsif (lc($Properties{'status'}{'value'} || '') eq 'cancelled') { } 0 7 7
1895 1 $Event{progress} = 'completed';
1896 }
1897 ▶ elsif (lc($Properties{status}{value} || '') eq 'in-process') {
Condition100%2/2
$Properties{'status'}{'value'} || ''
l!l
47
MC/DC100%1/1
$Properties{'status'}{'value'} || ''
$Properties{'status'}{'value'}
Truth table100%2/2
A
A= $Properties{'status'}{'value'}
Aresult
11
00
1898 4 $Event{progress} = 'in-process';
1899 }
1900 ▶ elsif (lc($Properties{status}{value} || '') eq 'cancelled') {
Condition50%1/2
$Properties{'status'}{'value'} || ''
l!l
07
MC/DC0%0/1
$Properties{'status'}{'value'} || ''
$Properties{'status'}{'value'}
Truth table50%1/2
A
A= $Properties{'status'}{'value'}
Aresult
11
00
1901 0 $Event{progress} = 'cancelled';
1902 }
1903 }
1904  
1905 426 return \%Event;
1906 }
1907  
1908 # jscalendar-icalendar-29 3.2: DTSTART, DUE and RECURRENCE-ID are DATE
1909 # only if showWithoutTime is true, there is no timeZone, and no time of
1910 # day appears anywhere: start, due, the durations, until and the override
1911 # keys. Otherwise an event shown without time keeps its time and zone and
1912 # says so with SHOW-WITHOUT-TIME.
1913 308 ▶sub _writesAsDate {
Subroutine _writesAsDate: called CC=16 SCAR=28.3
1914 308 my $Args = shift;
1915 308 ▶ return 0 unless $Args->{showWithoutTime};
Branch: 1 branch
BranchTrueFalseTotal
unless $Args->{"showWithoutTime"} 280 28 308
1916 28 ▶ return 0 if defined $Args->{timeZone} && length $Args->{timeZone};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Args->{"timeZone"} and length $Args->{"timeZone"} 7 21 28
Condition66%2/3
defined $Args->{"timeZone"} and length $Args->{"timeZone"}
!ll&&!rl&&r
2107
MC/DC50%1/2
defined $Args->{"timeZone"} and length $Args->{"timeZone"}
defined $Args->{"timeZone"} length $Args->{"timeZone"}
Truth table66%2/3
A and B
A= defined $Args->{"timeZone"}B= length $Args->{"timeZone"}
ABresult
0X0
100
111
1917 21 ▶ my $midnight = sub { !defined $_[0] || $_[0] !~ /T/ || $_[0] =~ /T00:00(?::00(?:\.0+)?)?\z/ };
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] && $_[0] =~ /T/ or $_[0] =~ /T00:00(?::00(?:\.0+)?)?\z/ 56 39 95
Condition66%2/3
defined $_[0] && $_[0] =~ /T/
!ll&&!rl&&r
56039
MC/DC50%1/2
defined $_[0] && $_[0] =~ /T/
defined $_[0] $_[0] =~ /T/
Truth table66%2/3
A && B
A= defined $_[0]B= $_[0] =~ /T/
ABresult
0X0
100
111
1918 21 ▶ my $whole_days = sub { !defined $_[0] || $_[0] !~ /T/ || $_[0] =~ /T(?:0+[HMS])*\z/ };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] && $_[0] =~ /T/ or $_[0] =~ /T(?:0+[HMS])*\z/ 38 2 40
Condition100%3/3
defined $_[0] && $_[0] =~ /T/
!ll&&!rl&&r
20182
MC/DC100%2/2
defined $_[0] && $_[0] =~ /T/
defined $_[0] $_[0] =~ /T/
Truth table100%3/3
A && B
A= defined $_[0]B= $_[0] =~ /T/
ABresult
0X0
100
111
1919 my $rule = ref $Args->{recurrenceRule} eq 'HASH' ? $Args->{recurrenceRule}
1920 21 ▶ : ref $Args->{recurrenceRules} eq 'ARRAY' ? $Args->{recurrenceRules}[0] : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $Args->{'recurrenceRule'} eq 'HASH' ? : 10 11 21
ref $Args->{'recurrenceRules'} eq 'ARRAY' ? : 0 11 11
1921 return 0 unless $midnight->($Args->{start}) && $midnight->($Args->{due})
1922 && $midnight->($Args->{recurrenceId}) && $midnight->($rule ? $rule->{until} : undef)
1923 21 ▶ && $whole_days->($Args->{duration}) && $whole_days->($Args->{estimatedDuration});
Branch: 2 branches
BranchTrueFalseTotal
unless &$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"}) 1 20 21
$rule ? : 10 10 20
Condition66%10/15
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef)
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"})
!ll&&!rl&&r
1020
MC/DC16%1/6
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"})
&$midnight($Args->{"start"}) &$midnight($Args->{"due"}) &$midnight($Args->{"recurrenceId"}) &$midnight($rule ? $rule->{"until"} : undef) &$whole_days($Args->{"duration"}) &$whole_days($Args->{"estimatedDuration"})
Truth table28%2/7
A and B and C and D and E and F
A= &$midnight($Args->{"start"})B= &$midnight($Args->{"due"})C= &$midnight($Args->{"recurrenceId"})D= &$midnight($rule ? $rule->{"until"} : undef)E= &$whole_days($Args->{"duration"})F= &$whole_days($Args->{"estimatedDuration"})
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1924 20 ▶ for my $key (keys %{ ref $Args->{recurrenceOverrides} eq 'HASH' ? $Args->{recurrenceOverrides} : {} }) {
Branch: 1 branch
BranchTrueFalseTotal
ref $Args->{'recurrenceOverrides'} eq 'HASH' ? : 6 14 20
1925 14 ▶ return 0 unless $midnight->($key);
Branch: 1 branch
BranchTrueFalseTotal
unless &$midnight($key) 0 14 14
1926 }
1927 20 return 1;
1928 }
1929  
1930 1378 ▶sub _getTimeZone {
Subroutine _getTimeZone: called CC=17 SCAR=28.8
1931 1378 my $Self = shift;
1932 1378 my ($Calendar, $Element) = @_;
1933  
1934 1378 ▶ if ($Element->{value} =~ m/Z$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->{"value"} =~ /Z$/) 911 467 1378
1935 911 return 'Etc/UTC';
1936 }
1937  
1938 467 my $TZID = $Element->{params}{tzid}[0];
1939  
1940 467 ▶ return undef unless $TZID;
Branch: 1 branch
BranchTrueFalseTotal
unless $TZID 67 400 467
1941  
1942 400 ▶ return $Self->{_tznamemap}{$TZID} if exists $Self->{_tznamemap}{$TZID};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Self->{"_tznamemap"}{$TZID} 247 153 400
1943  
1944 153 my %TzOffsets;
1945  
1946 153 ▶ foreach my $VTimeZone (@{$Calendar->{objects} || []}) {
Condition50%1/2
$Calendar->{'objects'} || []
l!l
1530
MC/DC0%0/1
$Calendar->{'objects'} || []
$Calendar->{'objects'}
Truth table50%1/2
A
A= $Calendar->{'objects'}
Aresult
11
00
1947 307 ▶ next unless lc $VTimeZone->{type} eq 'vtimezone';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $VTimeZone->{"type"} eq "vtimezone" 190 117 307
1948 117 ▶ next unless ($VTimeZone->{properties}{tzid}[0]{value} || '') eq $TZID;
Branch: 1 branch
BranchTrueFalseTotal
unless ($VTimeZone->{"properties"}{"tzid"}[0]{"value"} || "") eq $TZID 8 109 117
Condition50%1/2
$VTimeZone->{'properties'}{'tzid'}[0]{'value'} || ''
l!l
1170
MC/DC0%0/1
$VTimeZone->{'properties'}{'tzid'}[0]{'value'} || ''
$VTimeZone->{'properties'}{'tzid'}[0]{'value'}
Truth table50%1/2
A
A= $VTimeZone->{'properties'}{'tzid'}[0]{'value'}
Aresult
11
00
1949  
1950 109 ▶ foreach my $Observance (@{$VTimeZone->{objects} || []}) {
Condition50%1/2
$VTimeZone->{'objects'} || []
l!l
1090
MC/DC0%0/1
$VTimeZone->{'objects'} || []
$VTimeZone->{'objects'}
Truth table50%1/2
A
A= $VTimeZone->{'objects'}
Aresult
11
00
1951 217 ▶ next unless grep { (lc $Observance->{type} || '') eq $_ } qw{standard daylight};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {(lc $Observance->{"type"} || "") eq $_;} "standard", "daylight" 0 217 217
Condition50%1/2
lc $Observance->{'type'} || ''
l!l
4340
MC/DC0%0/1
lc $Observance->{'type'} || ''
lc $Observance->{'type'}
Truth table50%1/2
A
A= lc $Observance->{'type'}
Aresult
11
00
1952 217 ▶ next unless defined $Observance->{properties}{tzoffsetto}[0]{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Observance->{"properties"}{"tzoffsetto"}[0]{"value"} 0 217 217
1953  
1954 $TzOffsets{lc $Observance->{type}}
1955 217 = $Observance->{properties}{tzoffsetto}[0]{value};
1956 }
1957 }
1958  
1959 my $TimeZone = Text::JSCalendar::TimeZones->GetTimeZone(
1960 TZID => $TZID,
1961 Time => $Element->{value},
1962 (exists $TzOffsets{standard}
1963 ? (StandardTzOffsetTo => $TzOffsets{standard})
1964 : ()),
1965 (exists $TzOffsets{daylight}
1966 ? (DaylightTzOffsetTo => $TzOffsets{daylight})
1967 153 ▶ : ()),
Branch: 2 branches
BranchTrueFalseTotal
exists $TzOffsets{'standard'} ? : 109 44 153
exists $TzOffsets{'daylight'} ? : 108 45 153
Condition50%1/2
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ()) || undef
l!l
1530
MC/DC0%0/1
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ()) || undef
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ())
Truth table50%1/2
A
A= 'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ())
Aresult
11
00
1968 ) || undef;
1969  
1970 153 $Self->{_tznamemap}{$TZID} = $TimeZone;
1971 153 return $TimeZone;
1972 }
1973  
1974 688 ▶sub _wireDate {
Subroutine _wireDate: called CC=6 SCAR=18.2
1975 # format: YYYY-MM-DDTHH:MM:SS Z?
1976 688 my $isoDate = shift;
1977 688 ▶ my $timeZone = shift || $FLOATING;
Condition66%2/3
shift() || $Text::JSCalendar::FLOATING
l!l&&r!l&&!r
653350
MC/DC0%0/2
shift() || $Text::JSCalendar::FLOATING
shift() $Text::JSCalendar::FLOATING
Truth table66%2/3
A || B
A= shift()B= $Text::JSCalendar::FLOATING
ABresult
1X1
011
000
1978 688 ▶ confess "Invalid value (undefined) was not ISO8601" unless defined $isoDate;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $isoDate 1 687 688
1979 687 ▶ confess "Invalid value '$isoDate' was not ISO8601" unless $isoDate =~ m/^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(Z?)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $isoDate =~ /^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(Z?)$/i 0 687 687
1980 687 ▶ $timeZone = 'Etc/UTC' if $7;
Branch: 1 branch
BranchTrueFalseTotal
if $7 326 361 687
1981  
1982 687 ▶ my $Date = DateTime->_new(
Branch: 1 branch
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "hour", $4, "minute", $5, "second", $6, "time_zone", $timeZone, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${isoDate}'") 687 0 687
1983 year => $1,
1984 month => $2,
1985 day => $3,
1986 hour => $4,
1987 minute => $5,
1988 second => $6,
1989 time_zone => $timeZone,
1990 locale => $LOCALE,
1991 ) or confess "Invalid value '$isoDate'";
1992  
1993 687 return $Date;
1994 }
1995  
1996 1408 ▶sub _vDate {
Subroutine _vDate: called CC=6 SCAR=18.0
1997 # format: :YYYYMMDDTHHMMSS (floating)
1998 # format: :YYYYMMDDTHHMMSSZ (UTC)
1999 # format: ;TZID=X/Y:YYMMDDTHHMMSS (zoned)
2000 # format: ;TYPE=DATE:YYYYMMDD (but we don't know about that)
2001 1408 my $vDate = shift;
2002  
2003 1408 ▶ if ($vDate =~ m/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(\.\d+)?(Z?)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vDate =~ /^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(\.\d+)?(Z?)$/i) 1349 59 1408
2004 1349 ▶ my $Date = DateTime->_new(
Branch: 2 branches
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "hour", $4, "minute", $5, "second", $6, "time_zone", $8 eq "Z" ? $Text::JSCalendar::UTC : $Text::JSCalendar::FLOATING, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${vDate}' for DATETIME") 1349 0 1349
$8 eq 'Z' ? : 936 413 1349
2005 year => $1,
2006 month => $2,
2007 day => $3,
2008 hour => $4,
2009 minute => $5,
2010 second => $6,
2011 # ignore milliseconds in $7
2012 time_zone => ($8 eq 'Z' ? $UTC : $FLOATING),
2013 locale => $LOCALE,
2014 ) or confess "Invalid value '$vDate' for DATETIME";
2015  
2016 1349 return ($Date, 1);
2017 }
2018  
2019 59 ▶ if ($vDate =~ m/^(\d\d\d\d)(\d\d)(\d\d)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vDate =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) 58 1 59
2020 # all day
2021 58 ▶ my $Date = DateTime->_new(
Branch: 1 branch
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "time_zone", $Text::JSCalendar::FLOATING, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${vDate}' for DATE") 58 0 58
2022 year => $1,
2023 month => $2,
2024 day => $3,
2025 time_zone => $FLOATING,
2026 locale => $LOCALE,
2027 ) or confess "Invalid value '$vDate' for DATE";
2028  
2029 58 return ($Date, 0);
2030 }
2031  
2032 # we only support those two patterns
2033 1 confess "Date '$vDate' was neither a DATE or DATETIME value";
2034 }
2035  
2036 352 ▶sub _makeVTime {
Subroutine _makeVTime: called CC=1 SCAR=0.0
2037 352 my $Self = shift;
2038 352 my ($TimeZones, $wire, $tz, $IsAllDay) = @_;
2039  
2040 352 my $date = _wireDate($wire, $tz);
2041  
2042 352 return $Self->_makeVTimeObj($TimeZones, $date, $tz, $IsAllDay);
2043 }
2044  
2045 862 ▶sub _makeVTimeObj {
Subroutine _makeVTimeObj: called CC=4 SCAR=13.9
2046 862 my $Self = shift;
2047 862 my ($TimeZones, $date, $tz, $IsAllDay) = @_;
2048  
2049 # all day?
2050 862 ▶ if ($IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay) 34 828 862
2051 34 return [$date->strftime('%Y%m%d'), { VALUE => 'DATE' }];
2052 }
2053  
2054 # floating?
2055 828 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 24 804 828
2056 24 return [$date->strftime('%Y%m%dT%H%M%S')];
2057 }
2058  
2059 # UTC?
2060 804 ▶ if ($UTCLinks{$tz}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UTCLinks{$tz}) 556 248 804
2061 556 return [$date->strftime('%Y%m%dT%H%M%SZ')];
2062 }
2063  
2064 248 my $zone = $Self->tz($tz);
2065  
2066 248 $TimeZones->{$zone->name()} = 1;
2067  
2068 248 return [$date->strftime('%Y%m%dT%H%M%S'), { TZID => $zone->name() }];
2069 }
2070  
2071 352 ▶sub _makeZTime {
Subroutine _makeZTime: called CC=1 SCAR=0.0
2072 352 my ($Self, $date) = @_;
2073 352 return $Self->_makeVTime({}, $date, 'UTC');
2074 }
2075  
2076 64 ▶sub _makeLTime {
Subroutine _makeLTime: called CC=4 SCAR=13.9
2077 64 my $Self = shift;
2078 64 my ($TimeZones, $ltime, $tz, $IsAllDay) = @_;
2079  
2080 64 my $date = _wireDate($ltime, $Self->tz($tz));
2081  
2082 64 ▶ return [$date->strftime('%Y%m%d'), { VALUE => 'DATE' }] if $IsAllDay;
Branch: 1 branch
BranchTrueFalseTotal
if $IsAllDay 8 56 64
2083  
2084 56 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 3 53 56
2085 # floating
2086 3 return [$date->strftime('%Y%m%dT%H%M%S')];
2087 }
2088  
2089 53 ▶ if ($tz =~ m/UTC/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz =~ /UTC/i) 8 45 53
2090 8 return [$date->strftime('%Y%m%dT%H%M%SZ')];
2091 }
2092  
2093 # XXX - factor this crap out
2094 45 $TimeZones->{$tz} = 1;
2095  
2096 # XXX - use our cache
2097 45 my $zone = $Self->tz($tz);
2098  
2099 45 return [$date->strftime('%Y%m%dT%H%M%S'), { TZID => $zone->name() }];
2100 }
2101  
2102 268 ▶sub _argsToVEvents {
Subroutine _argsToVEvents: called CC=158 SCAR=51.2
2103 268 my $Self = shift;
2104 268 my ($TimeZones, $Args, $recurrenceData) = @_;
2105 268 my @VEvents;
2106  
2107 268 ▶ my $type = $Args->{'@type'} || '';
Condition50%1/2
$Args->{'@type'} || ''
l!l
2680
MC/DC0%0/1
$Args->{'@type'} || ''
$Args->{'@type'}
Truth table50%1/2
A
A= $Args->{'@type'}
Aresult
11
00
2108 268 my $is_task = $type eq 'Task';
2109 268 my $VEvent;
2110 268 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) { } 9 259 268
2111 9 eval { require Data::ICal::Entry::Todo };
2112 9 $VEvent = Data::ICal::Entry::Todo->new();
2113 } else {
2114 259 $VEvent = Data::ICal::Entry::Event->new();
2115 }
2116  
2117 # required properties
2118 268 my $transp = 'OPAQUE';
2119 268 ▶ if (defined $Args->{freeBusyStatus}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"freeBusyStatus"}) 54 214 268
2120 54 ▶ $transp = 'TRANSPARENT' if $Args->{freeBusyStatus} eq 'free';
Branch: 1 branch
BranchTrueFalseTotal
if $Args->{"freeBusyStatus"} eq "free" 54 0 54
2121 }
2122 $VEvent->add_properties(
2123 uid => $Args->{uid},
2124 268 ▶ sequence => ($Args->{sequence} || 0),
Branch: 1 branch
BranchTrueFalseTotal
$is_task ? : 9 259 268
Condition100%2/2
$Args->{'sequence'} || 0
l!l
38230
MC/DC100%1/1
$Args->{'sequence'} || 0
$Args->{'sequence'}
Truth table100%2/2
A
A= $Args->{'sequence'}
Aresult
11
00
2125 ($is_task ? () : (transp => $transp)),
2126 );
2127  
2128 268 ▶ if ($recurrenceData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurrenceData) 40 228 268
2129 40 my ($recurrenceId, $TopLevel) = @$recurrenceData;
2130 40 $VEvent->add_property('recurrence-id' => $Self->_makeLTime($TimeZones, $recurrenceId, $TopLevel->{timeZone}, _writesAsDate($TopLevel)));
2131 # (the same DATE-or-not decision as the master's DTSTART, -29 3.2)
2132 }
2133  
2134 # direct copy if properties exist
2135 268 ▶ if (defined $Args->{title} && $Args->{title} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"title"} and $Args->{"title"} ne "") 175 93 268
Condition100%3/3
defined $Args->{"title"} and $Args->{"title"} ne ""
!ll&&!rl&&r
921175
MC/DC100%2/2
defined $Args->{"title"} and $Args->{"title"} ne ""
defined $Args->{"title"} $Args->{"title"} ne ""
Truth table100%3/3
A and B
A= defined $Args->{"title"}B= $Args->{"title"} ne ""
ABresult
0X0
100
111
2136 175 my %lang;
2137 175 ▶ $lang{language} = $Args->{locale} if exists $Args->{locale};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"locale"} 25 150 175
2138 175 $VEvent->add_property(summary => [$Args->{title}, \%lang]);
2139 }
2140 268 ▶ if (defined $Args->{description} && $Args->{description} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"description"} and $Args->{"description"} ne "") 43 225 268
Condition100%3/3
defined $Args->{"description"} and $Args->{"description"} ne ""
!ll&&!rl&&r
218743
MC/DC100%2/2
defined $Args->{"description"} and $Args->{"description"} ne ""
defined $Args->{"description"} $Args->{"description"} ne ""
Truth table100%3/3
A and B
A= defined $Args->{"description"}B= $Args->{"description"} ne ""
ABresult
0X0
100
111
2141 43 my %lang;
2142 43 ▶ $lang{language} = $Args->{locale} if exists $Args->{locale};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"locale"} 24 19 43
2143 43 ▶ if ($Args->{descriptionContentType} && $Args->{descriptionContentType} ne 'text/plain') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{'descriptionContentType'} and $Args->{'descriptionContentType'} ne 'text/plain') { } 3 40 43
Condition66%2/3
$Args->{"descriptionContentType"} and $Args->{"descriptionContentType"} ne "text/plain"
!ll&&!rl&&r
4003
MC/DC50%1/2
$Args->{"descriptionContentType"} and $Args->{"descriptionContentType"} ne "text/plain"
$Args->{"descriptionContentType"} $Args->{"descriptionContentType"} ne "text/plain"
Truth table66%2/3
A and B
A= $Args->{"descriptionContentType"}B= $Args->{"descriptionContentType"} ne "text/plain"
ABresult
0X0
100
111
2144 # STYLED-DESCRIPTION for non-plain content types
2145 3 $VEvent->add_property('styled-description' => [$Args->{description}, { FMTTYPE => $Args->{descriptionContentType}, %lang }]);
2146 }
2147 else {
2148 40 $VEvent->add_property(description => [$Args->{description}, \%lang]);
2149 }
2150 }
2151  
2152 268 ▶ if ($Args->{status} and $Args->{status} ne 'confirmed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"status"} and $Args->{"status"} ne "confirmed") 6 262 268
Condition66%2/3
$Args->{"status"} and $Args->{"status"} ne "confirmed"
!ll&&!rl&&r
26206
MC/DC50%1/2
$Args->{"status"} and $Args->{"status"} ne "confirmed"
$Args->{"status"} $Args->{"status"} ne "confirmed"
Truth table66%2/3
A and B
A= $Args->{"status"}B= $Args->{"status"} ne "confirmed"
ABresult
0X0
100
111
2153 6 $VEvent->add_property('status', uc($Args->{status}));
2154 }
2155  
2156 # privacy -> CLASS
2157 268 ▶ if ($Args->{privacy} && $Args->{privacy} ne 'public') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"privacy"} and $Args->{"privacy"} ne "public") 5 263 268
Condition66%2/3
$Args->{"privacy"} and $Args->{"privacy"} ne "public"
!ll&&!rl&&r
26305
MC/DC50%1/2
$Args->{"privacy"} and $Args->{"privacy"} ne "public"
$Args->{"privacy"} $Args->{"privacy"} ne "public"
Truth table66%2/3
A and B
A= $Args->{"privacy"}B= $Args->{"privacy"} ne "public"
ABresult
0X0
100
111
2158 5 ▶ my $cls = $Args->{privacy} eq 'secret' ? 'CONFIDENTIAL' : uc($Args->{privacy});
Branch: 1 branch
BranchTrueFalseTotal
$Args->{'privacy'} eq 'secret' ? : 1 4 5
2159 5 $VEvent->add_property('class' => $cls);
2160 }
2161  
2162 # priority
2163 268 ▶ if ($Args->{priority} && $Args->{priority} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"priority"} and $Args->{"priority"} > 0) 12 256 268
Condition66%2/3
$Args->{"priority"} and $Args->{"priority"} > 0
!ll&&!rl&&r
256012
MC/DC50%1/2
$Args->{"priority"} and $Args->{"priority"} > 0
$Args->{"priority"} $Args->{"priority"} > 0
Truth table66%2/3
A and B
A= $Args->{"priority"}B= $Args->{"priority"} > 0
ABresult
0X0
100
111
2164 12 $VEvent->add_property('priority' => $Args->{priority});
2165 }
2166  
2167 # color
2168 # COLOR is a CSS3 color name or a six-digit hex value (icalendar-
2169 # jscalendar-extensions-09 2.2); any other CSS color has no iCalendar form
2170 268 ▶ my $Color = $Args->{color} ? eval { _fixColor($Args->{color}) } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$Args->{'color'} ? : 9 259 268
2171 268 ▶ if (defined $Color) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Color) 8 260 268
2172 8 $VEvent->add_property('color' => $Color);
2173 }
2174  
2175 # dates in UTC - stored in UTC
2176 268 ▶ $VEvent->add_property(created => $Self->_makeZTime($Args->{created})) if $Args->{created};
Branch: 1 branch
BranchTrueFalseTotal
if $Args->{"created"} 58 210 268
2177 268 ▶ $VEvent->add_property(dtstamp => $Self->_makeZTime($Args->{updated} || DateTime->now->iso8601()));
Condition66%2/3
$Args->{'updated'} || 'DateTime'->now->iso8601
l!l&&r!l&&!r
242260
MC/DC0%0/2
$Args->{'updated'} || 'DateTime'->now->iso8601
$Args->{'updated'} 'DateTime'->now->iso8601
Truth table66%2/3
A || B
A= $Args->{'updated'}B= 'DateTime'->now->iso8601
ABresult
1X1
011
000
2178  
2179 # dates in localtime - zones based on location
2180 268 my $EndTimeZone = $Args->{endTimeZone};
2181 268 ▶ my $locations = $Args->{locations} || {};
Condition100%2/2
$Args->{'locations'} || {}
l!l
24244
MC/DC100%1/1
$Args->{'locations'} || {}
$Args->{'locations'}
Truth table100%2/2
A
A= $Args->{'locations'}
Aresult
11
00
2182 268 foreach my $id (sort keys %$locations) {
2183 27 ▶ if ($locations->{$id}{name} && !$locations->{$id}{coordinates}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}) 19 8 27
Condition100%3/3
$locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}
!ll&&!rl&&r
5319
MC/DC100%2/2
$locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}
$locations->{$id}{"name"} not $locations->{$id}{"coordinates"}
Truth table100%3/3
A and not(B)
A= $locations->{$id}{"name"}B= not $locations->{$id}{"coordinates"}
ABresult
0X0
100
111
2184 # Only emit LOCATION if this entry doesn't also have coordinates
2185 # (coordinates with name go into X-APPLE-STRUCTURED-LOCATION with X-TITLE)
2186 19 $VEvent->add_property(location => $locations->{$id}{name});
2187 }
2188 # GEO from coordinates
2189 27 ▶ if ($locations->{$id}{coordinates} && $locations->{$id}{coordinates} =~ m{^geo:([-\d.]+),([-\d.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/) 8 19 27
Condition66%2/3
$locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
!ll&&!rl&&r
1908
MC/DC50%1/2
$locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
$locations->{$id}{"coordinates"} $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
Truth table66%2/3
A and B
A= $locations->{$id}{"coordinates"}B= $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
ABresult
0X0
100
111
2190 8 my ($lat, $lon) = ($1, $2);
2191 8 my $has_apple_meta = $locations->{$id}{name};
2192 8 ▶ if ($has_apple_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_apple_meta) { } 3 5 8
2193 # Emit X-APPLE-STRUCTURED-LOCATION (which implies GEO)
2194 3 my %asl_params = (VALUE => 'URI');
2195 3 ▶ $asl_params{'X-TITLE'} = $locations->{$id}{name} if $locations->{$id}{name};
Branch: 1 branch
BranchTrueFalseTotal
if $locations->{$id}{"name"} 3 0 3
2196 3 $VEvent->add_property('x-apple-structured-location' => [$locations->{$id}{coordinates}, \%asl_params]);
2197 }
2198 else {
2199 # Plain GEO without Apple metadata
2200 5 $VEvent->add_property('geo' => "$lat;$lon");
2201 }
2202 }
2203 }
2204  
2205 268 my $StartTimeZone = $Args->{timeZone};
2206 268 my $IsAllDay = _writesAsDate($Args);
2207 268 my $Start = _wireDate($Args->{start}, $StartTimeZone);
2208 267 $VEvent->add_property(dtstart => $Self->_makeVTimeObj($TimeZones, $Start, $StartTimeZone, $IsAllDay));
2209  
2210 # SHOW-WITHOUT-TIME for DATE-TIME events displayed as all-day
2211 # (jscalendar-icalendar-29 2.3.38, 3.2)
2212 267 ▶ if ($Args->{showWithoutTime} && !$IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"showWithoutTime"} and not $IsAllDay) 7 260 267
Condition100%3/3
$Args->{"showWithoutTime"} and not $IsAllDay
!ll&&!rl&&r
243177
MC/DC100%2/2
$Args->{"showWithoutTime"} and not $IsAllDay
$Args->{"showWithoutTime"} not $IsAllDay
Truth table100%3/3
A and not(B)
A= $Args->{"showWithoutTime"}B= not $IsAllDay
ABresult
0X0
100
111
2213 7 $VEvent->add_property('show-without-time' => ['TRUE', { VALUE => 'BOOLEAN' }]);
2214 }
2215  
2216 267 ▶ if ($Args->{duration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"duration"}) 243 24 267
2217 243 ▶ $EndTimeZone //= $StartTimeZone;
Condition100%3/3
$EndTimeZone //= $StartTimeZone
l!l&&r!l&&!r
421623
MC/DC100%2/2
$EndTimeZone //= $StartTimeZone
$EndTimeZone $StartTimeZone
Truth table100%3/3
A //= B
A= $EndTimeZoneB= $StartTimeZone
ABresult
1X1
011
000
2218 243 my $Duration = eval { DateTime::Format::ICal->parse_duration($Args->{duration}) };
2219 243 ▶ my $End = $Start->clone()->add($Duration) if $Duration;
Branch: 1 branch
BranchTrueFalseTotal
if $Duration 243 0 243
2220 243 ▶ $End->set_time_zone($EndTimeZone) if $EndTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
if $EndTimeZone 220 23 243
2221 243 $VEvent->add_property(dtend => $Self->_makeVTimeObj($TimeZones, $End, $EndTimeZone, $IsAllDay));
2222 }
2223  
2224 267 ▶ if (my $rule_def = $Args->{recurrenceRule}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rule_def = $Args->{"recurrenceRule"}) 42 225 267
2225 42 my %Recurrence = $Self->_makeRecurrence($rule_def, $IsAllDay, $StartTimeZone);
2226  
2227 # RFC 2445 4.3.10 - FREQ is the first part of the RECUR value type.
2228 # RFC 5545 3.3.10 - FREQ should be first to ensure backward compatibility.
2229 my $rule = join(';',
2230 ('FREQ=' . delete($Recurrence{FREQ})),
2231 41 (map { "$_=$Recurrence{$_}" } keys %Recurrence),
2232 );
2233 41 $VEvent->add_property(rrule => $rule);
2234 }
2235  
2236 266 my $Synthetic = isSyntheticMaster($Args);
2237 266 ▶ if ($Args->{recurrenceOverrides}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"recurrenceOverrides"}) 32 234 266
2238 32 foreach my $recurrenceId (sort keys %{$Args->{recurrenceOverrides}}) {
2239 59 my $val = $Args->{recurrenceOverrides}{$recurrenceId};
2240 59 ▶ if ($val->{excluded}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val->{'excluded'}) { } 13 46 59
elsif (keys %$val or $Synthetic) { } 40 6 46
2241 # (no master to carry an EXDATE: the instance is simply not written)
2242 13 ▶ next if $Synthetic;
Branch: 1 branch
BranchTrueFalseTotal
if $Synthetic 1 12 13
2243 12 $VEvent->add_property(exdate => $Self->_makeLTime($TimeZones, $recurrenceId, $StartTimeZone, $IsAllDay));
2244 }
2245 ▶ elsif (keys %$val or $Synthetic) {
Condition100%3/3
keys %$val or $Synthetic
l!l&&r!l&&!r
3916
MC/DC100%2/2
keys %$val or $Synthetic
keys %$val $Synthetic
Truth table100%3/3
A or B
A= keys %$valB= $Synthetic
ABresult
1X1
011
000
2246 40 my $SubEvent = $Self->_maximise($Args, $val, $recurrenceId);
2247 40 push @VEvents, $Self->_argsToVEvents($TimeZones, $SubEvent, [$recurrenceId, $Args]);
2248 }
2249 else {
2250 6 $VEvent->add_property(rdate => $Self->_makeLTime($TimeZones, $recurrenceId, $StartTimeZone, $IsAllDay));
2251 }
2252 }
2253 }
2254  
2255 266 ▶ if ($Args->{alerts}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"alerts"}) 36 230 266
2256 # (an untitled event still gets a readable DESCRIPTION; the title was
2257 # interpolated undefined, which died under FATAL warnings)
2258 36 ▶ my $Title = $Args->{title} // '';
Condition100%2/2
$Args->{"title"} // ""
l!l
2511
MC/DC100%1/1
$Args->{"title"} // ""
$Args->{"title"}
Truth table100%2/2
A
A= $Args->{"title"}
Aresult
11
00
2259 36 for my $id (sort keys %{$Args->{alerts}}) {
2260 # a bad alert drops only itself (see errors())
2261 56 my $ok = eval {
2262 56 my $Alert = $Args->{alerts}{$id};
2263  
2264 56 ▶ my $trigger = $Alert->{trigger} // {};
Condition50%1/2
$Alert->{"trigger"} // {}
l!l
560
MC/DC0%0/1
$Alert->{"trigger"} // {}
$Alert->{"trigger"}
Truth table50%1/2
A
A= $Alert->{"trigger"}
Aresult
11
00
2265 56 ▶ my $triggerType = $trigger->{'@type'} // 'OffsetTrigger';
Condition100%2/2
$trigger->{"\@type"} // "OffsetTrigger"
l!l
515
MC/DC100%1/1
$trigger->{"\@type"} // "OffsetTrigger"
$trigger->{"\@type"}
Truth table100%2/2
A
A= $trigger->{"\@type"}
Aresult
11
00
2266 56 ▶ my $action = $Alert->{action} // 'display';
Condition100%2/2
$Alert->{"action"} // "display"
l!l
4511
MC/DC100%1/1
$Alert->{"action"} // "display"
$Alert->{"action"}
Truth table100%2/2
A
A= $Alert->{"action"}
Aresult
11
00
2267  
2268 56 my $VAlarm;
2269 56 ▶ if ($action eq 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'email') { } 5 51 56
2270 5 $VAlarm = Data::ICal::Entry::Alarm::Email->new();
2271 5 $VAlarm->add_property(summary => "Event alert: '$Title'");
2272 5 $VAlarm->add_property(description => "Event alert: '$Title'");
2273 5 ▶ if ($Args->{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"organizerCalendarAddress"}) 2 3 5
2274 2 $VAlarm->add_property(attendee => $Args->{organizerCalendarAddress});
2275 }
2276 }
2277 else {
2278 51 $VAlarm = Data::ICal::Entry::Alarm::Display->new();
2279 }
2280  
2281 56 ▶ if ($triggerType eq 'OffsetTrigger') {
Branch: 2 branches
BranchTrueFalseTotal
if ($triggerType eq 'OffsetTrigger') { } 47 9 56
elsif ($triggerType eq 'AbsoluteTrigger') { } 8 1 9
2282 47 ▶ my $Offset = $trigger->{offset} // 'PT0S';
Condition50%1/2
$trigger->{"offset"} // "PT0S"
l!l
470
MC/DC0%0/1
$trigger->{"offset"} // "PT0S"
$trigger->{"offset"}
Truth table50%1/2
A
A= $trigger->{"offset"}
Aresult
11
00
2283 47 ▶ my $RelTo = $trigger->{relativeTo} // 'start';
Condition100%2/2
$trigger->{"relativeTo"} // "start"
l!l
3710
MC/DC100%1/1
$trigger->{"relativeTo"} // "start"
$trigger->{"relativeTo"}
Truth table100%2/2
A
A= $trigger->{"relativeTo"}
Aresult
11
00
2284 # Offset may have a leading '-' sign (already encoded in the duration string)
2285 47 ▶ my $Sign = ($Offset =~ s/^-//) ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$Offset =~ s/^-// ? : 40 7 47
2286 47 ▶ my $Loc1 = $RelTo eq 'end' ? "ends" : "starts";
Branch: 1 branch
BranchTrueFalseTotal
$RelTo eq 'end' ? : 8 39 47
2287 47 ▶ my $Loc2 = $RelTo eq 'end' ? "ended" : "started";
Branch: 1 branch
BranchTrueFalseTotal
$RelTo eq 'end' ? : 8 39 47
2288 47 ▶ my $Minutes = eval { DateTime::Format::ICal->parse_duration(uc $Offset)->in_units('minutes') } // 0;
Condition50%1/2
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } } // 0
l!l
470
MC/DC0%0/1
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } } // 0
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } }
Truth table50%1/2
A
A= eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } }
Aresult
11
00
2289 47 ▶ if ($action ne 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "email") 42 5 47
2290 42 ▶ $VAlarm->add_properties(
Branch: 1 branch
BranchTrueFalseTotal
$Sign eq '-' ? : 35 7 42
2291 description => (($Sign eq '-')
2292 ? "'$Title' $Loc1 in $Minutes minutes"
2293 : "'$Title' $Loc2 $Minutes minutes ago"),
2294 );
2295 }
2296 47 $VAlarm->add_property(uid => $id);
2297 47 ▶ if ($RelTo eq 'end') {
Branch: 1 branch
BranchTrueFalseTotal
if ($RelTo eq 'end') { } 8 39 47
2298 8 $VAlarm->add_property(trigger => ["${Sign}$Offset", { RELATED => 'END' }]);
2299 }
2300 else {
2301 39 $VAlarm->add_property(trigger => "${Sign}$Offset");
2302 }
2303 }
2304 elsif ($triggerType eq 'AbsoluteTrigger') {
2305 8 ▶ my $When = $trigger->{when} // '';
Condition50%1/2
$trigger->{"when"} // ""
l!l
80
MC/DC0%0/1
$trigger->{"when"} // ""
$trigger->{"when"}
Truth table50%1/2
A
A= $trigger->{"when"}
Aresult
11
00
2306 8 ▶ if ($action ne 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "email") 8 0 8
2307 8 $VAlarm->add_properties(
2308 description => "Event alert: '$Title'",
2309 );
2310 }
2311 8 $VAlarm->add_property(uid => $id);
2312 8 $VAlarm->add_property(trigger => [
2313 $Self->_makeZTime($When)->[0],
2314 { 'VALUE' => 'DATE-TIME' }
2315 ]);
2316 }
2317 else {
2318 1 confess "Unknown trigger type $triggerType";
2319 }
2320  
2321 55 ▶ if ($Alert->{acknowledged}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alert->{"acknowledged"}) 8 47 55
2322 8 $VAlarm->add_property(acknowledged => $Self->_makeZTime($Alert->{acknowledged}));
2323 }
2324  
2325 55 $VEvent->add_entry($VAlarm);
2326 55 1;
2327 };
2328 56 ▶ $Self->_error($Args->{uid}, 'Alert', $@, $id) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 55 56
2329 }
2330 }
2331  
2332 266 my %namemap;
2333 my %keymap;
2334 266 my %sentbymap;
2335 266 ▶ if ($Args->{participants}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"participants"}) 56 210 266
2336 56 foreach my $partid (sort keys %{$Args->{participants}}) {
2337 107 my $Attendee = $Args->{participants}{$partid};
2338 # jscalendarbis: a Participant's address is its calendarAddress URI;
2339 # "email" is the JSCalendar 1.0 form, still accepted.
2340 my $Uri = $Attendee->{calendarAddress}
2341 107 ▶ // (defined $Attendee->{email} ? "mailto:$Attendee->{email}" : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $Attendee->{'email'} ? : 1 0 1
Condition100%2/2
$Attendee->{"calendarAddress"} // (defined $Attendee->{"email"} ? qq[mailto:$Attendee->{"email"}] : undef)
l!l
1061
MC/DC100%1/1
$Attendee->{"calendarAddress"} // (defined $Attendee->{"email"} ? qq[mailto:$Attendee->{"email"}] : undef)
$Attendee->{"calendarAddress"}
Truth table100%2/2
A
A= $Attendee->{"calendarAddress"}
Aresult
11
00
2342 107 ▶ next unless defined $Uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Uri 0 107 107
2343  
2344 # jscalendar-icalendar 2.3.4: JSID carries the participant's key,
2345 # and may be left out only when the reader would arrive at the same
2346 # key anyway. Without it, an override patching
2347 # participants/<key>/... no longer finds its participant.
2348 107 my $DefaultKey = _defaultParticipantKey($Uri);
2349 107 ▶ my $NeedJSID = !(defined $DefaultKey and $DefaultKey eq $partid);
Condition66%2/3
defined $DefaultKey && $DefaultKey eq $partid
!ll&&!rl&&r
04364
MC/DC50%1/2
defined $DefaultKey && $DefaultKey eq $partid
defined $DefaultKey $DefaultKey eq $partid
Truth table66%2/3
A && B
A= defined $DefaultKeyB= $DefaultKey eq $partid
ABresult
0X0
100
111
2350 107 ▶ $keymap{lc $Uri} //= $partid if $NeedJSID;
Branch: 1 branch
BranchTrueFalseTotal
if $NeedJSID 43 64 107
Condition66%2/3
$keymap{lc $Uri} //= $partid
l!l&&r!l&&!r
1420
MC/DC0%0/2
$keymap{lc $Uri} //= $partid
$keymap{lc $Uri} $partid
Truth table66%2/3
A //= B
A= $keymap{lc $Uri}B= $partid
ABresult
1X1
011
000
2351  
2352 107 my %AttendeeProps;
2353 107 ▶ $AttendeeProps{JSID} = $partid if $NeedJSID;
Branch: 1 branch
BranchTrueFalseTotal
if $NeedJSID 43 64 107
2354 107 ▶ if ($Attendee->{"name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"name"}) 67 40 107
2355 67 $AttendeeProps{"CN"} = $Attendee->{"name"};
2356 67 $namemap{lc $Uri} = $Attendee->{"name"};
2357 }
2358  
2359 my $roles = ref($Attendee->{roles}) eq 'HASH'
2360 ? $Attendee->{roles}
2361 0 ▶ : { map { $_ => 1 } @{$Attendee->{roles} || []} };
Branch: 1 branch
BranchTrueFalseTotal
ref $Attendee->{'roles'} eq 'HASH' ? : 104 3 107
Condition50%1/2
$Attendee->{'roles'} || []
l!l
03
MC/DC0%0/1
$Attendee->{'roles'} || []
$Attendee->{'roles'}
Truth table50%1/2
A
A= $Attendee->{'roles'}
Aresult
11
00
2362  
2363 # jscalendarbis: every participant is an ATTENDEE unless the
2364 # ORGANIZER fully represents it (jscalendar-icalendar 3.6)
2365 107 ▶ unless ($roles->{attendee}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($roles->{"attendee"}) 30 77 107
2366 30 my $OrgUri = $Args->{organizerCalendarAddress};
2367 next if defined $OrgUri and lc $OrgUri eq lc $Uri
2368 23 and not grep { $_ ne 'owner' } keys %$roles
2369 30 ▶ and not grep { !$OrganizerOnly{$_} } keys %$Attendee;
Branch: 1 branch
BranchTrueFalseTotal
if defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee) 22 8 30
Condition88%8/9
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee)
!ll&&!rl&&r
7122
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles)
!ll&&!rl&&r
7023
defined $OrgUri and lc $OrgUri eq lc $Uri
!ll&&!rl&&r
2523
MC/DC75%3/4
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee)
defined $OrgUri lc $OrgUri eq lc $Uri not grep({$_ ne "owner";} keys %$roles) not grep({not $OrganizerOnly{$_};} keys %$Attendee)
Truth table80%4/5
A and B and not(C) and not(D)
A= defined $OrgUriB= lc $OrgUri eq lc $UriC= not grep({$_ ne "owner";} keys %$roles)D= not grep({not $OrganizerOnly{$_};} keys %$Attendee)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2370 }
2371  
2372 85 ▶ $AttendeeProps{"CUTYPE"} = uc $Attendee->{"kind"} if defined $Attendee->{"kind"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"kind"} 7 78 85
2373 85 ▶ $AttendeeProps{"RSVP"} = "TRUE" if $Attendee->{"expectReply"};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"expectReply"} 5 80 85
2374 85 ▶ $AttendeeProps{"X-SEQUENCE"} = $Attendee->{"scheduleSequence"} if defined $Attendee->{"scheduleSequence"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"scheduleSequence"} 8 77 85
2375 85 ▶ $AttendeeProps{"X-DTSTAMP"} = $Self->_makeZTime($Attendee->{"scheduleUpdated"}) if defined $Attendee->{"scheduleUpdated"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"scheduleUpdated"} 9 76 85
2376 85 foreach my $prop (keys %AttendeeProps) {
2377 119 ▶ delete $AttendeeProps{$prop} if $AttendeeProps{$prop} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $AttendeeProps{$prop} eq "" 0 119 119
2378 }
2379 85 ▶ if ($roles->{owner}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($roles->{'owner'}) { } 26 59 85
elsif ($roles->{'chair'}) { } 1 58 59
elsif ($roles->{'optional'}) { } 7 51 58
elsif ($roles->{'informational'}) { } 1 50 51
2380 26 $AttendeeProps{ROLE} = 'OWNER';
2381 }
2382 elsif ($roles->{chair}) {
2383 1 $AttendeeProps{ROLE} = 'CHAIR';
2384 }
2385 elsif ($roles->{optional}) {
2386 7 $AttendeeProps{ROLE} = 'OPT-PARTICIPANT';
2387 }
2388 elsif ($roles->{informational}) {
2389 1 $AttendeeProps{ROLE} = 'NON-PARTICIPANT';
2390 }
2391 # default is REQ-PARTICIPANT
2392 85 ▶ $AttendeeProps{"SCHEDULE-AGENT"} = uc($Attendee->{scheduleAgent}) if $Attendee->{scheduleAgent};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"scheduleAgent"} 2 83 85
2393 85 ▶ if ($Attendee->{delegatedFrom} && ref($Attendee->{delegatedFrom}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH") 4 81 85
Condition66%2/3
$Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH"
!ll&&!rl&&r
8104
MC/DC50%1/2
$Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH"
$Attendee->{"delegatedFrom"} ref $Attendee->{"delegatedFrom"} eq "HASH"
Truth table66%2/3
A and B
A= $Attendee->{"delegatedFrom"}B= ref $Attendee->{"delegatedFrom"} eq "HASH"
ABresult
0X0
100
111
2394 4 $AttendeeProps{"DELEGATED-FROM"} = [ sort keys %{$Attendee->{delegatedFrom}} ];
2395 }
2396 85 ▶ if ($Attendee->{delegatedTo} && ref($Attendee->{delegatedTo}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH") 4 81 85
Condition66%2/3
$Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH"
!ll&&!rl&&r
8104
MC/DC50%1/2
$Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH"
$Attendee->{"delegatedTo"} ref $Attendee->{"delegatedTo"} eq "HASH"
Truth table66%2/3
A and B
A= $Attendee->{"delegatedTo"}B= ref $Attendee->{"delegatedTo"} eq "HASH"
ABresult
0X0
100
111
2397 4 $AttendeeProps{"DELEGATED-TO"} = [ sort keys %{$Attendee->{delegatedTo}} ];
2398 }
2399  
2400 85 ▶ $AttendeeProps{PARTSTAT} = uc $Attendee->{"participationStatus"} if $Attendee->{"participationStatus"};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"participationStatus"} 49 36 85
2401 85 ▶ if (defined $Attendee->{sentBy} and length $Attendee->{sentBy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}) 2 83 85
Condition66%2/3
defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}
!ll&&!rl&&r
8302
MC/DC50%1/2
defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}
defined $Attendee->{"sentBy"} length $Attendee->{"sentBy"}
Truth table66%2/3
A and B
A= defined $Attendee->{"sentBy"}B= length $Attendee->{"sentBy"}
ABresult
0X0
100
111
2402 2 $AttendeeProps{"SENT-BY"} = _mailto($Attendee->{sentBy});
2403 2 $sentbymap{lc $Uri} = $Attendee->{sentBy};
2404 }
2405  
2406 85 $VEvent->add_property(attendee => [ $Uri, \%AttendeeProps ]);
2407 }
2408 }
2409 266 ▶ if ($Args->{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"organizerCalendarAddress"}) 51 215 266
2410 51 my $OrgUri = $Args->{organizerCalendarAddress};
2411 51 my %OrgProps;
2412 51 my $CN = $namemap{lc $OrgUri};
2413 51 ▶ $OrgProps{CN} = $CN if $CN;
Branch: 1 branch
BranchTrueFalseTotal
if $CN 30 21 51
2414 # the organizer's participant may not be written as an ATTENDEE, so
2415 # its key must ride on the ORGANIZER (jscalendar-icalendar 2.3.29)
2416 51 ▶ $OrgProps{JSID} = $keymap{lc $OrgUri} if defined $keymap{lc $OrgUri};
Branch: 1 branch
BranchTrueFalseTotal
if defined $keymap{lc $OrgUri} 16 35 51
2417 # the Event's sentBy, else the organizer participant's (-29 3.7)
2418 51 ▶ my $SentBy = $Args->{sentBy} // $sentbymap{lc $OrgUri};
Condition66%2/3
$Args->{"sentBy"} // $sentbymap{lc $OrgUri}
l!l&&r!l&&!r
2049
MC/DC50%1/2
$Args->{"sentBy"} // $sentbymap{lc $OrgUri}
$Args->{"sentBy"} $sentbymap{lc $OrgUri}
Truth table66%2/3
A // B
A= $Args->{"sentBy"}B= $sentbymap{lc $OrgUri}
ABresult
1X1
011
000
2419 51 ▶ $OrgProps{"SENT-BY"} = _mailto($SentBy) if defined $SentBy and length $SentBy;
Branch: 1 branch
BranchTrueFalseTotal
if defined $SentBy and length $SentBy 2 49 51
Condition66%2/3
defined $SentBy and length $SentBy
!ll&&!rl&&r
4902
MC/DC50%1/2
defined $SentBy and length $SentBy
defined $SentBy length $SentBy
Truth table66%2/3
A and B
A= defined $SentByB= length $SentBy
ABresult
0X0
100
111
2420 51 ▶ $VEvent->add_property(organizer => [ $OrgUri, %OrgProps ? \%OrgProps : () ]);
Branch: 1 branch
BranchTrueFalseTotal
%OrgProps ? : 35 16 51
2421 }
2422  
2423 266 ▶ if ($Args->{links}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"links"}) 19 247 266
2424 # jscalendar-icalendar 3.4: the property follows "rel" (whose default
2425 # is "enclosure", jscalendarbis 1.5.11): enclosure -> ATTACH, icon ->
2426 # IMAGE, the first describedby -> URL, anything else -> LINK. The
2427 # title is FILENAME on ATTACH and IMAGE, LABEL on URL and LINK; LINKREL
2428 # goes on LINK only. JSID carries the key unless the reader would
2429 # arrive at it anyway.
2430 19 my $HaveURL = 0;
2431 19 foreach my $key (sort keys %{$Args->{links}}) {
2432 34 my $Link = $Args->{links}{$key};
2433 34 ▶ next unless ref $Link eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Link eq "HASH" 0 34 34
2434 34 ▶ my $Url = $Link->{href} // next;
Condition50%1/2
$Link->{"href"} // (next)
l!l
340
MC/DC0%0/1
$Link->{"href"} // (next)
$Link->{"href"}
Truth table50%1/2
A
A= $Link->{"href"}
Aresult
11
00
2435 34 ▶ my $rel = $Link->{rel} // 'enclosure';
Condition100%2/2
$Link->{"rel"} // "enclosure"
l!l
259
MC/DC100%1/1
$Link->{"rel"} // "enclosure"
$Link->{"rel"}
Truth table100%2/2
A
A= $Link->{"rel"}
Aresult
11
00
2436 34 my %Props;
2437 34 ▶ $Props{JSID} = $key unless $key eq sha1_hex(lc $Url);
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq &sha1_hex(lc $Url) 24 10 34
2438 34 my $Name;
2439 34 ▶ if ($rel eq 'enclosure') {
Branch: 3 branches
BranchTrueFalseTotal
if ($rel eq 'enclosure') { } 20 14 34
elsif ($rel eq 'icon') { } 3 11 14
elsif ($rel eq 'describedby' and not $HaveURL++) { } 6 5 11
2440 20 $Name = 'attach';
2441 20 ▶ $Props{FILENAME} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 3 17 20
2442 20 ▶ $Props{SIZE} = $Link->{size} if defined $Link->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"size"} 8 12 20
2443 }
2444 elsif ($rel eq 'icon') {
2445 3 $Name = 'image';
2446 3 $Props{VALUE} = 'URI';
2447 3 ▶ $Props{FILENAME} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 3 0 3
2448 3 ▶ $Props{SIZE} = $Link->{size} if defined $Link->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"size"} 0 3 3
2449 3 ▶ my @display = grep { $Link->{display}{$_} } sort keys %{ ref $Link->{display} eq 'HASH' ? $Link->{display} : {} };
Branch: 1 branch
BranchTrueFalseTotal
ref $Link->{'display'} eq 'HASH' ? : 3 0 3
2450 3 ▶ $Props{DISPLAY} = join(',', map { uc } @display) if @display;
Branch: 1 branch
BranchTrueFalseTotal
if @display 3 0 3
2451 }
2452 ▶ elsif ($rel eq 'describedby' && !$HaveURL++) {
Condition100%3/3
$rel eq "describedby" and not $HaveURL++
!ll&&!rl&&r
326
MC/DC100%2/2
$rel eq "describedby" and not $HaveURL++
$rel eq "describedby" not $HaveURL++
Truth table100%3/3
A and not(B)
A= $rel eq "describedby"B= not $HaveURL++
ABresult
0X0
100
111
2453 6 $Name = 'url';
2454 6 ▶ $Props{LABEL} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 2 4 6
2455 }
2456 else {
2457 5 $Name = 'link';
2458 5 $Props{VALUE} = 'URI';
2459 5 $Props{LINKREL} = $rel;
2460 5 ▶ $Props{LABEL} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 4 1 5
2461 }
2462 34 ▶ $Props{FMTTYPE} = $Link->{contentType} if defined $Link->{contentType} && $Name ne 'url';
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"contentType"} and $Name ne "url" 16 18 34
Condition66%2/3
defined $Link->{"contentType"} and $Name ne "url"
!ll&&!rl&&r
18016
MC/DC50%1/2
defined $Link->{"contentType"} and $Name ne "url"
defined $Link->{"contentType"} $Name ne "url"
Truth table66%2/3
A and B
A= defined $Link->{"contentType"}B= $Name ne "url"
ABresult
0X0
100
111
2463 34 ▶ $VEvent->add_property($Name => [ $Url, %Props ? \%Props : () ]);
Branch: 1 branch
BranchTrueFalseTotal
%Props ? : 29 5 34
2464 }
2465 }
2466  
2467 266 ▶ if ($Args->{relatedTo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"relatedTo"}) 12 254 266
2468 12 foreach my $uid (keys %{$Args->{relatedTo}}) {
2469 21 my $relation = $Args->{relatedTo}{$uid}{relation};
2470 21 foreach my $key (keys %$relation) {
2471 22 ▶ $key = uc($key) if grep { $_ eq $key } qw(first next parent child);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $key;} "first", "next", "parent", "child" 19 3 22
2472 22 my %Props;
2473 22 ▶ $Props{RELTYPE} = $key unless $key eq 'PARENT';
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "PARENT" 11 11 22
2474 22 $VEvent->add_property('RELATED-TO' => [ $uid, \%Props ]);
2475 }
2476 }
2477 }
2478  
2479 266 ▶ if ($Args->{keywords}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"keywords"}) 4 262 266
2480 4 my @items = sort keys %{$Args->{keywords}};
2481 4 $VEvent->add_property('CATEGORIES', join(',', @items));
2482 }
2483  
2484 # virtualLocations -> CONFERENCE
2485 266 ▶ if ($Args->{virtualLocations}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"virtualLocations"}) 7 259 266
2486 7 foreach my $id (sort keys %{$Args->{virtualLocations}}) {
2487 10 my $vloc = $Args->{virtualLocations}{$id};
2488 10 ▶ next unless $vloc->{uri};
Branch: 1 branch
BranchTrueFalseTotal
unless $vloc->{"uri"} 0 10 10
2489 10 my %params = ('VALUE' => 'URI');
2490 10 $params{'X-JMAP-ID'} = $id;
2491 10 ▶ if ($vloc->{features} && ref($vloc->{features}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($vloc->{"features"} and ref $vloc->{"features"} eq "HASH") 8 2 10
Condition66%2/3
$vloc->{"features"} and ref $vloc->{"features"} eq "HASH"
!ll&&!rl&&r
208
MC/DC50%1/2
$vloc->{"features"} and ref $vloc->{"features"} eq "HASH"
$vloc->{"features"} ref $vloc->{"features"} eq "HASH"
Truth table66%2/3
A and B
A= $vloc->{"features"}B= ref $vloc->{"features"} eq "HASH"
ABresult
0X0
100
111
2492 8 my @feats = sort keys %{$vloc->{features}};
2493 8 ▶ $params{FEATURE} = join(',', map { uc $_ } @feats) if @feats;
Branch: 1 branch
BranchTrueFalseTotal
if @feats 8 0 8
2494 }
2495 10 ▶ $params{LABEL} = $vloc->{name} if defined $vloc->{name} && $vloc->{name} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $vloc->{"name"} and $vloc->{"name"} ne "" 8 2 10
Condition66%2/3
defined $vloc->{"name"} and $vloc->{"name"} ne ""
!ll&&!rl&&r
208
MC/DC50%1/2
defined $vloc->{"name"} and $vloc->{"name"} ne ""
defined $vloc->{"name"} $vloc->{"name"} ne ""
Truth table66%2/3
A and B
A= defined $vloc->{"name"}B= $vloc->{"name"} ne ""
ABresult
0X0
100
111
2496 10 $VEvent->add_property(conference => [$vloc->{uri}, \%params]);
2497 }
2498 }
2499  
2500 # Task-specific properties (VTODO)
2501 266 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) 8 258 266
2502 8 ▶ if ($Args->{due}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"due"}) 6 2 8
2503 6 $VEvent->add_property(due => $Self->_makeLTime($TimeZones, $Args->{due}, $StartTimeZone, $IsAllDay));
2504 }
2505 8 ▶ if (defined $Args->{percentComplete}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"percentComplete"}) 5 3 8
2506 5 $VEvent->add_property('percent-complete' => $Args->{percentComplete});
2507 }
2508 8 ▶ if ($Args->{estimatedDuration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"estimatedDuration"}) 1 7 8
2509 1 $VEvent->add_property('estimated-duration' => $Args->{estimatedDuration});
2510 }
2511 8 ▶ if ($Args->{progress} && $Args->{progress} eq 'completed') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Args->{'progress'} and $Args->{'progress'} eq 'completed') { } 1 7 8
elsif ($Args->{'progress'} and $Args->{'progress'} eq 'in-process') { } 2 9 11
Condition100%3/3
$Args->{"progress"} and $Args->{"progress"} eq "completed"
!ll&&!rl&&r
431
MC/DC100%2/2
$Args->{"progress"} and $Args->{"progress"} eq "completed"
$Args->{"progress"} $Args->{"progress"} eq "completed"
Truth table100%3/3
A and B
A= $Args->{"progress"}B= $Args->{"progress"} eq "completed"
ABresult
0X0
100
111
2512 1 ▶ $VEvent->add_property(completed => $Self->_makeZTime($Args->{updated} || DateTime->now->iso8601()));
Condition33%1/3
$Args->{'updated'} || 'DateTime'->now->iso8601
l!l&&r!l&&!r
100
MC/DC0%0/2
$Args->{'updated'} || 'DateTime'->now->iso8601
$Args->{'updated'} 'DateTime'->now->iso8601
Truth table33%1/3
A || B
A= $Args->{'updated'}B= 'DateTime'->now->iso8601
ABresult
1X1
011
000
2513 }
2514 ▶ elsif ($Args->{progress} && $Args->{progress} eq 'in-process') {
Condition100%3/3
$Args->{"progress"} and $Args->{"progress"} eq "in-process"
!ll&&!rl&&r
412
MC/DC100%2/2
$Args->{"progress"} and $Args->{"progress"} eq "in-process"
$Args->{"progress"} $Args->{"progress"} eq "in-process"
Truth table100%3/3
A and B
A= $Args->{"progress"}B= $Args->{"progress"} eq "in-process"
ABresult
0X0
100
111
2515 2 $VEvent->add_property(status => 'IN-PROCESS');
2516 }
2517 }
2518  
2519 # a synthetic master (see SYNTHETIC_MASTER) has no component of its
2520 # own: only its instances are written
2521 266 ▶ unshift @VEvents, $VEvent unless $Synthetic;
Branch: 1 branch
BranchTrueFalseTotal
unless $Synthetic 261 5 266
2522  
2523 266 return @VEvents;
2524 }
2525  
2526 =head2 $self->eventsToVCalendar(@Events)
2527  
2528 Convert a set of events (one or multiple) into an ical file)
2529  
2530 Returns a string
2531  
2532 e.g.
2533  
2534 print $jscal->eventsToVCalendar(@Events);
2535  
2536 =cut
2537  
2538 232 ▶sub eventsToVCalendar {
Subroutine eventsToVCalendar: called CC=1 SCAR=0.0
Pod documented
2539 232 my $Self = shift;
2540 232 $Self->_resetDiagnostics();
2541 232 my $VCalendar = $Self->_buildVCalendar(\@_);
2542 232 ▶ return $Self->_withICalWarnings(sub { $VCalendar->as_string() });
Subroutine __ANON__: called CC=1 SCAR=0.0
2543 }
2544  
2545 1 ▶sub _argsToVCalendar {
Subroutine _argsToVCalendar: called CC=1 SCAR=0.0
2546 1 my $Self = shift;
2547 1 $Self->_resetDiagnostics();
2548 1 return $Self->_buildVCalendar(@_);
2549 }
2550  
2551 233 ▶sub _buildVCalendar {
Subroutine _buildVCalendar: called CC=1 SCAR=0.0
2552 233 my $Self = shift;
2553 233 my $Item = shift;
2554 233 my %ExtraProp = @_;
2555 233 ▶ return $Self->_withICalWarnings(sub { $Self->_buildVCalendarInner($Item, %ExtraProp) });
Subroutine __ANON__: called CC=1 SCAR=0.0
2556 }
2557  
2558 233 ▶sub _buildVCalendarInner {
Subroutine _buildVCalendarInner: called CC=15 SCAR=27.1
2559 233 my $Self = shift;
2560 233 my $Item = shift;
2561 233 my %ExtraProp = @_;
2562  
2563 233 my $VCalendar = Data::ICal->new();
2564 233 my $havepid = 0;
2565  
2566 233 foreach my $extra (keys %ExtraProp) {
2567 0 $VCalendar->add_properties($extra => $ExtraProp{$extra});
2568 }
2569 233 $VCalendar->add_properties(calscale => 'GREGORIAN');
2570  
2571 233 my @VEvents;
2572 my %TimeZones;
2573 233 ▶ foreach my $Args (ref $Item eq 'ARRAY' ? @$Item : $Item) {
Branch: 1 branch
BranchTrueFalseTotal
ref $Item eq 'ARRAY' ? : 233 0 233
2574 # each object on its own: one that cannot be written is left out
2575 # (and reported by errors()), not the whole calendar
2576 229 my %Zones;
2577 229 my @Converted = eval {
2578 229 ▶ die "not a JSCalendar object\n" unless ref $Args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Args eq "HASH" 1 228 229
2579 228 $Self->_argsToVEvents(\%Zones, $Args);
2580 };
2581 229 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 3 226 229
2582 3 ▶ my $type = ref $Args eq 'HASH' && ($Args->{'@type'} // '') eq 'Task' ? 'Task' : 'Event';
Branch: 1 branch
BranchTrueFalseTotal
ref $Args eq 'HASH' && ($Args->{'@type'} // '') eq 'Task' ? : 1 2 3
Condition80%4/5
ref $Args eq "HASH" and ($Args->{"\@type"} // "") eq "Task"
!ll&&!rl&&r
111
$Args->{"\@type"} // ""
l!l
20
MC/DC50%1/2
ref $Args eq "HASH" and ($Args->{"\@type"} // "") eq "Task"
ref $Args eq "HASH" $Args->{"\@type"}
Truth table66%2/3
A and B
A= ref $Args eq "HASH"B= $Args->{"\@type"}
ABresult
0X0
100
111
2583 3 ▶ $Self->_error(ref $Args eq 'HASH' ? $Args->{uid} : undef, $type, $err);
Branch: 1 branch
BranchTrueFalseTotal
ref $Args eq 'HASH' ? : 2 1 3
2584 3 next;
2585 }
2586 226 push @VEvents, @Converted;
2587 226 @TimeZones{keys %Zones} = values %Zones;
2588 226 ▶ if (not $havepid and $Args->{prodId}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $havepid and $Args->{"prodId"}) 146 80 226
Condition100%3/3
not $havepid and $Args->{"prodId"}
!ll&&!rl&&r
278146
MC/DC100%2/2
not $havepid and $Args->{"prodId"}
not $havepid $Args->{"prodId"}
Truth table100%3/3
not(A) and B
A= not $havepidB= $Args->{"prodId"}
ABresult
0X0
100
111
2589 146 $VCalendar->add_properties('prodid' => $Args->{prodId});
2590 146 $havepid = 1;
2591 }
2592 }
2593  
2594 # add timezone parts first
2595 233 foreach my $Zone (sort keys %TimeZones) {
2596 105 my $VTimeZone = Text::JSCalendar::TimeZones->GetVTimeZone($Zone);
2597 105 ▶ next unless $VTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
unless $VTimeZone 0 105 105
2598 105 $VCalendar->add_entry($VTimeZone);
2599 }
2600  
2601 # then the events
2602 233 foreach my $VEvent (@VEvents) {
2603 261 $VCalendar->add_entry($VEvent);
2604 }
2605  
2606 233 _sanitizeEntry($VCalendar);
2607  
2608 233 return $VCalendar;
2609 }
2610  
2611 # Data::ICal escapes newlines in values, but not a lone CR, and puts
2612 # parameter values out verbatim, so a CR or LF from the event data
2613 # would start a new content line. RFC 5545 allows no control characters
2614 # other than HTAB in either, so strip them before serialising.
2615 863 ▶sub _sanitizeEntry {
Subroutine _sanitizeEntry: called CC=8 SCAR=20.9
2616 863 my $Entry = shift;
2617  
2618 863 foreach my $Props (values %{$Entry->properties}) {
2619 4325 foreach my $Prop (@$Props) {
2620 4379 my $value = $Prop->value;
2621 4379 ▶ if (defined $value and not ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not ref $value) 4379 0 4379
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
004379
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
2622 4379 $value =~ s/\r\n?/\n/g;
2623 4379 $value =~ s/[\x00-\x08\x0b-\x1f\x7f]//g;
2624 4379 $Prop->value($value);
2625 }
2626  
2627 4379 my %params;
2628 4379 ▶ while (my ($name, $val) = each %{$Prop->parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$Prop->parameters;}) 796 4379 5175
2629 $params{$name} = ref $val eq 'ARRAY'
2630 796 ▶ ? [ map { _sanitizeParam($_) } @$val ]
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 17 779 796
2631 : _sanitizeParam($val);
2632 }
2633 4379 $Prop->parameters(\%params);
2634 }
2635 }
2636  
2637 863 _sanitizeEntry($_) for @{$Entry->entries};
2638 }
2639  
2640 797 ▶sub _sanitizeParam {
Subroutine _sanitizeParam: called CC=2 SCAR=7.0
2641 797 my $val = shift;
2642 797 ▶ return $val unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 797 797
2643 797 $val =~ s/[\r\n]+/ /g;
2644 # DQUOTE can't be escaped either; Data::ICal drops it with a warning
2645 797 $val =~ s/[\x00-\x08\x0a-\x1f\x7f"]//g;
2646 797 return $val;
2647 }
2648  
2649 42 ▶sub _makeRecurrence {
Subroutine _makeRecurrence: called CC=37 SCAR=41.5
2650 42 my $Self = shift;
2651 42 my ($Args, $IsAllDay, $TZ) = @_;
2652  
2653 42 my %Recurrence;
2654  
2655 # validate simple recurrence properties {{{
2656  
2657 42 ▶ unless (ref($Args) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args eq "HASH") 0 42 42
2658 0 confess 'Invalid recurrence';
2659 }
2660  
2661 42 ▶ if ($Args->{frequency}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{'frequency'}) { } 42 0 42
2662 42 ▶ unless ($ValidFrequency{$Args->{frequency}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidFrequency{$Args->{"frequency"}}) 1 41 42
2663 1 confess "Invalid recurrence frequency ($Args->{frequency})";
2664 }
2665  
2666 41 $Recurrence{FREQ} = uc($Args->{frequency});
2667 }
2668 else {
2669 0 confess 'Recurrence frequency not specified';
2670 }
2671  
2672 # (numbers are copied before they meet a pattern or a join: either
2673 # stringifies the value it is given, and that would turn the caller's
2674 # 2 into "2" when it next encodes the object as JSON)
2675 41 ▶ if (defined $Args->{interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"interval"}) 7 34 41
2676 7 my $interval = $Args->{interval};
2677 7 ▶ unless ($interval =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($interval =~ /^\d+$/) 0 7 7
2678 0 confess "Invalid recurrence interval ($interval)";
2679 }
2680  
2681 7 ▶ if ($interval == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval == 0) 0 7 7
2682 0 confess "Recurrence interval is out of range ($interval)";
2683 }
2684  
2685 7 ▶ if ($interval > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval > 1) 7 0 7
2686 7 $Recurrence{INTERVAL} = $interval;
2687 }
2688 }
2689  
2690 41 ▶ if (defined $Args->{firstDayOfWeek}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"firstDayOfWeek"}) 1 40 41
2691 1 ▶ unless ($ValidDay{$Args->{firstDayOfWeek}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{$Args->{"firstDayOfWeek"}}) 0 1 1
2692 0 confess "Invalid recurrence firstDayOfWeek ($Args->{firstDayOfWeek})";
2693 }
2694  
2695 1 ▶ unless ($Args->{firstDayOfWeek} eq 'mo') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Args->{"firstDayOfWeek"} eq "mo") 1 0 1
2696 1 $Recurrence{WKST} = uc $Args->{firstDayOfWeek};
2697 }
2698 }
2699  
2700 41 ▶ if ($Args->{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"byDay"}) 11 30 41
2701 11 ▶ unless (ref($Args->{byDay}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{"byDay"} eq "ARRAY") 0 11 11
2702 0 confess 'Invalid recurrence byDay';
2703 }
2704  
2705 11 ▶ unless (@{$Args->{byDay}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{"byDay"};}) 0 11 11
2706 0 confess 'Recurrence byDay is empty';
2707 }
2708  
2709 11 $Recurrence{BYDAY} = join(',', map{ _byDay2BYDAY($_) } @{$Args->{byDay}});
2710 }
2711  
2712 41 ▶ if ($Args->{byMonth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"byMonth"}) 7 34 41
2713 7 ▶ unless (ref($Args->{byMonth}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{"byMonth"} eq "ARRAY") 0 7 7
2714 0 confess 'Invalid recurrence byMonth';
2715 }
2716  
2717 7 ▶ unless (@{$Args->{byMonth}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{"byMonth"};}) 0 7 7
2718 0 confess 'Recurrence byMonth is empty';
2719 }
2720  
2721 7 my @BYMONTHS;
2722  
2723 7 foreach my $byMonthArg (@{$Args->{byMonth}}) {
2724 10 my $byMonth = $byMonthArg;
2725 10 ▶ unless ($byMonth =~ /^(\d+)L?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($byMonth =~ /^(\d+)L?$/i) 0 10 10
2726 0 confess "Recurrence byMonth is not a number with optional L ($byMonth)";
2727 }
2728 10 my $monthNum = $1;
2729 10 ▶ unless ($monthNum >= 1 and $monthNum <= 13) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($monthNum >= 1 and $monthNum <= 13) 0 10 10
Condition33%1/3
$monthNum >= 1 and $monthNum <= 13
!ll&&!rl&&r
0010
MC/DC0%0/2
$monthNum >= 1 and $monthNum <= 13
$monthNum >= 1 $monthNum <= 13
Truth table33%1/3
A and B
A= $monthNum >= 1B= $monthNum <= 13
ABresult
0X0
100
111
2730 # not sure if 13 is OK
2731 0 confess "Recurrence byMonth is too high ($monthNum)";
2732 }
2733  
2734 10 push @BYMONTHS, $byMonth;
2735 }
2736  
2737 7 $Recurrence{BYMONTH} = join ',', @BYMONTHS;
2738 }
2739  
2740 41 ▶ if (defined $Args->{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"count"}) 15 26 41
2741 15 ▶ if (defined $Args->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"until"}) 0 15 15
2742 0 confess 'Recurrence count and until cannot both be set';
2743 }
2744  
2745 15 my $count = $Args->{count};
2746 15 ▶ unless ($count =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($count =~ /^\d+$/) 0 15 15
2747 0 confess "Invalid recurrence count ($count)";
2748 }
2749  
2750 15 $Recurrence{COUNT} = $count;
2751 }
2752  
2753 41 ▶ if ($Args->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"until"}) 4 37 41
2754 4 my $Until = _wireDate($Args->{until}, $Self->tz($TZ));
2755  
2756 4 ▶ if ($IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay) { } 2 2 4
2757 2 $Recurrence{UNTIL} = $Until->strftime('%Y%m%d');
2758 }
2759 else {
2760 # API is in Localtime, but both iCloud and Google use 'Z' times as per
2761 # rfc2445, so we'll copy them for compatibility.
2762 2 $Until->set_time_zone($UTC);
2763 2 $Recurrence{UNTIL} = $Until->strftime('%Y%m%dT%H%M%SZ');
2764 }
2765 }
2766  
2767 41 ▶ if ($Args->{rscale}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"rscale"}) 6 35 41
2768 6 $Recurrence{RSCALE} = uc $Args->{rscale};
2769 6 ▶ $Recurrence{SKIP} = uc $Args->{skip} if exists $Args->{skip};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"skip"} 6 0 6
2770 }
2771  
2772 # }}}
2773  
2774 # validate generic recurrence properties {{{
2775  
2776 41 foreach my $Property (keys %RecurrenceProperties) {
2777 287 my $Name = $RecurrenceProperties{$Property}{name};
2778  
2779 287 ▶ if ($Args->{$Name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{$Name}) 25 262 287
2780 25 ▶ unless (ref($Args->{$Name}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{$Name} eq "ARRAY") 0 25 25
2781 0 confess "Invalid recurrence $Name";
2782 }
2783  
2784 25 ▶ unless (@{$Args->{$Name}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{$Name};}) 0 25 25
2785 0 confess "Recurrence $Name is empty";
2786 }
2787  
2788 25 my @Values;
2789  
2790 25 foreach my $ValueArg (@{$Args->{$Name}}) {
2791 43 my $Value = $ValueArg;
2792 my ($Valid, $Min) = $RecurrenceProperties{$Property}{signed}
2793 43 ▶ ? ('[-+]?[1-9]\d*', ($RecurrenceProperties{$Property}{max} * -1))
Branch: 1 branch
BranchTrueFalseTotal
$RecurrenceProperties{$Property}{'signed'} ? : 26 17 43
2794 : ('\d+', 0);
2795  
2796 43 ▶ unless ($Value =~ /^$Valid$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value =~ /^$Valid$/) 0 43 43
2797 0 confess "Invalid recurrence $Name ($Value)";
2798 }
2799  
2800 43 ▶ unless (($Min <= $Value) and ($Value <= $RecurrenceProperties{$Property}{max})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}) 0 43 43
Condition33%1/3
$Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}
!ll&&!rl&&r
0043
MC/DC0%0/2
$Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}
$Min <= $Value $Value <= $RecurrenceProperties{$Property}{"max"}
Truth table33%1/3
A and B
A= $Min <= $ValueB= $Value <= $RecurrenceProperties{$Property}{"max"}
ABresult
0X0
100
111
2801 0 confess "Recurrence $Name is out of range ($Value)";
2802 }
2803  
2804 43 push @Values, $Value;
2805 }
2806  
2807 25 $Recurrence{uc $Property} = join ',', @Values;
2808 }
2809 }
2810  
2811 # }}}
2812  
2813 41 return %Recurrence;
2814 }
2815  
2816 =head2 $self->vcalendarToEvents($Data)
2817  
2818 Convert a text vcalendar (either a single event or an entire ical file) into an array of events.
2819  
2820 Returns an array (not arrayref) of Events in UID order.
2821  
2822 e.g.
2823  
2824 foreach my $Event ($CalDAV->vcalendarToEvents($Data)) {
2825 # ...
2826 }
2827  
2828 =cut
2829  
2830 56 ▶sub _insert_override {
Subroutine _insert_override: called CC=10 SCAR=23.0
2831 56 my $Event = shift;
2832 56 my $recurrenceId = shift;
2833 56 my $Recurrence = shift;
2834 56 my $KeepEmpty = shift;
2835  
2836 56 my %override;
2837 56 my %oldkeys = map { $_ => 1 } keys %$Event;
2838 56 foreach my $Key (sort keys %$Recurrence) {
2839 672 delete $oldkeys{$Key};
2840 672 ▶ next if $MustBeTopLevel{$Key}; # XXX - check safeeq and die?
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$Key} 236 436 672
2841 436 ▶ if ($Key eq 'start') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Key eq "start") 56 380 436
2842 # special case, it's the recurrence-id
2843 56 ▶ next if _safeeq($Recurrence->{start}, $recurrenceId);
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($Recurrence->{"start"}, $recurrenceId) 23 33 56
2844 33 $override{start} = $Recurrence->{start};
2845 33 next;
2846 }
2847 380 ▶ next if _safeeq($Recurrence->{$Key}, $Event->{$Key});
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($Recurrence->{$Key}, $Event->{$Key}) 288 92 380
2848 92 _add_override(\%override, _quotekey($Key), $Recurrence->{$Key}, $Event->{$Key});
2849 }
2850  
2851 56 foreach my $Key (sort keys %oldkeys) {
2852 99 ▶ next if $MustBeTopLevel{$Key};
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$Key} 87 12 99
2853 12 $override{$Key} = $JSON::null;
2854 }
2855  
2856 # in theory should never happen, but you could edit something back to be identical
2857 56 ▶ return unless %override or $KeepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
unless %override or $KeepEmpty 4 52 56
Condition66%2/3
%override or $KeepEmpty
l!l&&r!l&&!r
5204
MC/DC50%1/2
%override or $KeepEmpty
%override $KeepEmpty
Truth table66%2/3
A or B
A= %overrideB= $KeepEmpty
ABresult
1X1
011
000
2858 52 $Event->{recurrenceOverrides}{$recurrenceId} = \%override;
2859 }
2860  
2861 392 ▶sub vcalendarToEvents {
Subroutine vcalendarToEvents: called CC=13 SCAR=25.7
Pod documented
2862 392 my $Self = shift;
2863 392 my $Data = shift;
2864  
2865 # Internal caches need to be invalidated on each item read! A bit evil really...
2866 392 delete $Self->{_tznamemap};
2867 392 $Self->_resetDiagnostics();
2868  
2869 392 my %map;
2870 my %exceptions;
2871 392 my $Events = $Self->_getEventsFromVCalendar($Data);
2872  
2873 392 foreach my $Event (@$Events) {
2874 426 my $uid = $Event->{uid};
2875 426 ▶ if ($Event->{_recurrenceObj}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Event->{'_recurrenceObj'}) { } 55 371 426
elsif ($map{$uid}) { } 1 370 371
2876 55 push @{$exceptions{$uid}}, $Event;
2877 }
2878 elsif ($map{$uid}) {
2879 # it looks like sometimes Google doesn't remember to put the Recurrence ID
2880 # on additional recurrences after the first one, which is going to screw up
2881 # pretty badly because if the date has changed, then we can't even notice
2882 # which recurrent it was SUPPOSED to be. *sigh*.
2883 1 ▶ $Self->_warning($uid, uc($Event->{'@type'} eq 'Task' ? 'VTODO' : 'VEVENT'),
Branch: 1 branch
BranchTrueFalseTotal
$Event->{'@type'} eq 'Task' ? : 0 1 1
2884 "a second component without RECURRENCE-ID; read as an instance at its DTSTART");
2885 1 push @{$exceptions{$uid}}, $Event;
2886 1 $map{$uid}{_dirty} = 1;
2887 }
2888 else {
2889 370 $map{$uid} = $Event;
2890 }
2891 }
2892  
2893 392 foreach my $uid (keys %exceptions) {
2894 38 ▶ unless ($map{$uid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($map{$uid}) 9 29 38
2895 # create a synthetic top-level, and say so (see SYNTHETIC_MASTER),
2896 # from the earliest instance, so that it does not depend on the
2897 # order of the components (the writer sorts them)
2898 9 my ($First) = sort { _compareInstances($a, $b) } @{$exceptions{$uid}};
2899 $map{$uid} = {
2900 SYNTHETIC_MASTER() => $JSON::true,
2901 uid => $uid,
2902 # required at top level, but may be different in recurrences
2903 # so not in MustBeTopLevel
2904 start => $First->{start},
2905 updated => $First->{updated},
2906 version => $First->{version},
2907 9 };
2908 9 ▶ $map{$uid}{timeZone} = $First->{timeZone} unless $First->{showWithoutTime};
Branch: 1 branch
BranchTrueFalseTotal
unless $First->{"showWithoutTime"} 9 0 9
2909 9 foreach my $key (keys %MustBeTopLevel) {
2910 117 ▶ $map{$uid}{$key} = $First->{$key} if exists $First->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $First->{$key} 40 77 117
2911 }
2912 }
2913 38 foreach my $SubEvent (@{$exceptions{$uid}}) {
2914 56 my $recurrenceId = $SubEvent->{start};
2915 56 ▶ if ($SubEvent->{_recurrenceObj}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SubEvent->{"_recurrenceObj"}) 55 1 56
2916 55 my $Date = delete $SubEvent->{_recurrenceObj};
2917 55 ▶ $Date->set_time_zone($map{$uid}{timeZone}) if $map{$uid}{timeZone};
Branch: 1 branch
BranchTrueFalseTotal
if $map{$uid}{"timeZone"} 52 3 55
2918 55 $recurrenceId = $Date->iso8601();
2919 }
2920 # every instance of a synthetic master is an override, even one
2921 # that patches nothing: there is no rule or RDATE to recur from
2922 56 _insert_override($map{$uid}, $recurrenceId, $SubEvent, isSyntheticMaster($map{$uid}));
2923 }
2924 }
2925  
2926 392 return map { $map{$_} } sort keys %map;
2927 }
2928  
2929 =head2 $self->instance($Event, $recurrenceId)
2930  
2931 The occurrence of C<$Event> with the given recurrence id (a LocalDateTime
2932 as used for C<recurrenceOverrides> keys, C<YYYY-MM-DDTHH:MM:SS>), as an
2933 object of its own: a copy of the master with the override patch for that
2934 id, if any, applied (PatchObject paths such as
2935 C<participants/p1/participationStatus> included, as the writer applies
2936 them), C<recurrenceId> set, C<recurrenceIdTimeZone> set to the master's
2937 C<timeZone> if it has one, C<start> the patch's if it moves the
2938 occurrence and the recurrence id otherwise, and C<recurrenceRule> and
2939 C<recurrenceOverrides> removed. A patch cannot change the properties an
2940 occurrence must share with its master (C<uid>, C<@type>,
2941 C<recurrenceRule>, ...; the same ones the writer ignores).
2942  
2943 Returns undef if the occurrence is excluded, or if C<$Event> is a
2944 synthetic master (see above) and the id is not one of its instances.
2945 It does not check that the id is an occurrence of the rule: that is
2946 what C<occurrences> is for. C<$Event> is not changed. May be called as
2947 a class method.
2948  
2949 =cut
2950  
2951 6 ▶sub instance {
Subroutine instance: called CC=11 SCAR=24.2
Pod documented
2952 6 my ($Self, $Event, $recurrenceId) = @_;
2953 6 ▶ croak 'instance: not an event' unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 6 6
2954 6 ▶ my $rid = _localDateTime($recurrenceId) // croak "instance: invalid recurrenceId";
Condition50%1/2
_localDateTime($recurrenceId) // croak("instance: invalid recurrenceId")
l!l
60
MC/DC0%0/1
_localDateTime($recurrenceId) // croak("instance: invalid recurrenceId")
_localDateTime($recurrenceId)
Truth table50%1/2
A
A= _localDateTime($recurrenceId)
Aresult
11
00
2955  
2956 6 ▶ my $Overrides = ref $Event->{recurrenceOverrides} eq 'HASH' ? $Event->{recurrenceOverrides} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $Event->{'recurrenceOverrides'} eq 'HASH' ? : 6 0 6
2957 6 my $Patch = $Overrides->{$rid};
2958 6 ▶ $Patch = undef unless ref $Patch eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Patch eq "HASH" 2 4 6
2959 6 ▶ return undef if $Patch and $Patch->{excluded};
Branch: 1 branch
BranchTrueFalseTotal
if $Patch and $Patch->{"excluded"} 1 5 6
Condition100%3/3
$Patch and $Patch->{"excluded"}
!ll&&!rl&&r
231
MC/DC100%2/2
$Patch and $Patch->{"excluded"}
$Patch $Patch->{"excluded"}
Truth table100%3/3
A and B
A= $PatchB= $Patch->{"excluded"}
ABresult
0X0
100
111
2960 5 ▶ return undef if !$Patch and isSyntheticMaster($Event);
Branch: 1 branch
BranchTrueFalseTotal
if not $Patch and isSyntheticMaster($Event) 1 4 5
Condition100%3/3
not $Patch and isSyntheticMaster($Event)
!ll&&!rl&&r
311
MC/DC100%2/2
not $Patch and isSyntheticMaster($Event)
not $Patch isSyntheticMaster($Event)
Truth table100%3/3
not(A) and B
A= not $PatchB= isSyntheticMaster($Event)
ABresult
0X0
100
111
2961  
2962 4 ▶ my $Instance = $Self->_maximise($Event, $Patch || {}, $rid);
Condition100%2/2
$Patch || {}
l!l
31
MC/DC100%1/1
$Patch || {}
$Patch
Truth table100%2/2
A
A= $Patch
Aresult
11
00
2963 4 delete $Instance->{excluded};
2964 4 $Instance->{recurrenceId} = $rid;
2965 4 ▶ if (defined $Event->{timeZone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Event->{'timeZone'}) { } 4 0 4
2966 4 $Instance->{recurrenceIdTimeZone} = $Event->{timeZone};
2967 }
2968 else {
2969 0 delete $Instance->{recurrenceIdTimeZone};
2970 }
2971 4 return $Instance;
2972 }
2973  
2974 =head2 $self->occurrences($Event, after => $from, before => $to, max => $n)
2975  
2976 The recurrence ids of C<$Event> (LocalDateTimes, C<YYYY-MM-DDTHH:MM:SS>,
2977 the form of C<recurrenceOverrides> keys) that are at or after C<after>
2978 and before C<before>, in order. Both bounds are LocalDateTimes in the
2979 event's own time zone (a trailing C<Z> is ignored, a bare date means its
2980 midnight) and either may be left out. These are:
2981  
2982 =over
2983  
2984 =item * the event's C<start>, which is always the first occurrence
2985 (jscalendarbis-22 3.3.3.1), and for a C<recurrenceRule> every date-time
2986 the rule produces from it, with every rule property this module reads:
2987 C<frequency>, C<interval>, C<firstDayOfWeek>, C<byDay> (with
2988 C<nthOfPeriod>), C<byMonthDay>, C<byMonth>, C<byYearDay>, C<byWeekNo>,
2989 C<byHour>, C<byMinute>, C<bySecond>, C<bySetPosition>, C<count>,
2990 C<until>, and C<skip> (C<rscale> must be C<gregorian>, the default;
2991 another one dies),
2992  
2993 =item * plus every C<recurrenceOverrides> key that is not excluded and
2994 that the rule does not produce (an added occurrence, iCalendar's RDATE),
2995  
2996 =item * minus every key whose patch sets C<excluded>.
2997  
2998 =back
2999  
3000 For a synthetic master (see above) they are its instances: its override
3001 keys, minus the excluded ones.
3002  
3003 C<max> (default 5000) bounds the number returned, so an unbounded rule
3004 without C<before> still ends; a rule that stops matching (C<byMonthDay>
3005 30 in C<byMonth> 2) ends once 400 years pass without an occurrence.
3006 Returns an empty list for an event without C<start>. May be called as
3007 a class method.
3008  
3009 =cut
3010  
3011 18 our $MaxOccurrences = 5000;
3012  
3013 33 ▶sub occurrences {
Subroutine occurrences: called CC=23 SCAR=32.5
Pod documented
3014 33 my ($Self, $Event, %Opts) = @_;
3015 33 ▶ croak 'occurrences: not an event' unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 33 33
3016 33 ▶ my $max = $Opts{max} // $MaxOccurrences;
Condition66%2/3
$Opts{"max"} // $Text::JSCalendar::MaxOccurrences
l!l&&r!l&&!r
1320
MC/DC0%0/2
$Opts{"max"} // $Text::JSCalendar::MaxOccurrences
$Opts{"max"} $Text::JSCalendar::MaxOccurrences
Truth table66%2/3
A // B
A= $Opts{"max"}B= $Text::JSCalendar::MaxOccurrences
ABresult
1X1
011
000
3017 33 ▶ croak 'occurrences: max must be a positive integer' unless $max =~ /^\d+$/ and $max > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $max =~ /^\d+$/ and $max > 0 0 33 33
Condition33%1/3
$max =~ /^\d+$/ and $max > 0
!ll&&!rl&&r
0033
MC/DC0%0/2
$max =~ /^\d+$/ and $max > 0
$max =~ /^\d+$/ $max > 0
Truth table33%1/3
A and B
A= $max =~ /^\d+$/B= $max > 0
ABresult
0X0
100
111
3018 33 my ($after, $before);
3019 33 ▶ if (defined $Opts{after}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Opts{"after"}) 3 30 33
3020 3 ▶ $after = _localDateTime($Opts{after}) // croak "occurrences: invalid after ($Opts{after})";
Condition50%1/2
_localDateTime($Opts{"after"}) // croak(qq[occurrences: invalid after ($Opts{"after"})])
l!l
30
MC/DC0%0/1
_localDateTime($Opts{"after"}) // croak(qq[occurrences: invalid after ($Opts{"after"})])
_localDateTime($Opts{"after"})
Truth table50%1/2
A
A= _localDateTime($Opts{"after"})
Aresult
11
00
3021 }
3022 33 ▶ if (defined $Opts{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Opts{"before"}) 2 31 33
3023 2 ▶ $before = _localDateTime($Opts{before}) // croak "occurrences: invalid before ($Opts{before})";
Condition50%1/2
_localDateTime($Opts{"before"}) // croak(qq[occurrences: invalid before ($Opts{"before"})])
l!l
20
MC/DC0%0/1
_localDateTime($Opts{"before"}) // croak(qq[occurrences: invalid before ($Opts{"before"})])
_localDateTime($Opts{"before"})
Truth table50%1/2
A
A= _localDateTime($Opts{"before"})
Aresult
11
00
3024 }
3025 5138 ▶ my $inRange = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
3026 5138 my $rid = shift;
3027 5138 ▶ return 0 if defined $after and $rid lt $after;
Branch: 1 branch
BranchTrueFalseTotal
if defined $after and $rid lt $after 6 5132 5138
Condition100%3/3
defined $after and $rid lt $after
!ll&&!rl&&r
512486
MC/DC100%2/2
defined $after and $rid lt $after
defined $after $rid lt $after
Truth table100%3/3
A and B
A= defined $afterB= $rid lt $after
ABresult
0X0
100
111
3028 5132 ▶ return 0 if defined $before and $rid ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $rid ge $before 0 5132 5132
Condition66%2/3
defined $before and $rid ge $before
!ll&&!rl&&r
512660
MC/DC0%0/2
defined $before and $rid ge $before
defined $before $rid ge $before
Truth table66%2/3
A and B
A= defined $beforeB= $rid ge $before
ABresult
0X0
100
111
3029 5132 return 1;
3030 33 };
3031  
3032 33 ▶ my $Overrides = ref $Event->{recurrenceOverrides} eq 'HASH' ? $Event->{recurrenceOverrides} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $Event->{'recurrenceOverrides'} eq 'HASH' ? : 3 30 33
3033 33 my (%excluded, @added);
3034 33 foreach my $key (keys %$Overrides) {
3035 6 ▶ my $rid = _localDateTime($key) // next;
Condition50%1/2
_localDateTime($key) // (next)
l!l
60
MC/DC0%0/1
_localDateTime($key) // (next)
_localDateTime($key)
Truth table50%1/2
A
A= _localDateTime($key)
Aresult
11
00
3036 6 my $Patch = $Overrides->{$key};
3037 6 ▶ if (ref $Patch eq 'HASH' and $Patch->{excluded}) { $excluded{$rid} = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Patch eq 'HASH' and $Patch->{'excluded'}) { } 1 5 6
Condition66%2/3
ref $Patch eq "HASH" and $Patch->{"excluded"}
!ll&&!rl&&r
051
MC/DC50%1/2
ref $Patch eq "HASH" and $Patch->{"excluded"}
ref $Patch eq "HASH" $Patch->{"excluded"}
Truth table66%2/3
A and B
A= ref $Patch eq "HASH"B= $Patch->{"excluded"}
ABresult
0X0
100
111
3038 5 else { push @added, $rid }
3039 }
3040  
3041 33 my @found;
3042 33 ▶ unless (isSyntheticMaster($Event)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isSyntheticMaster($Event)) 32 1 33
3043 32 ▶ my $start = _localDateTime($Event->{start}) // return ();
Condition50%1/2
_localDateTime($Event->{"start"}) // (return ())
l!l
320
MC/DC0%0/1
_localDateTime($Event->{"start"}) // (return ())
_localDateTime($Event->{"start"})
Truth table50%1/2
A
A= _localDateTime($Event->{"start"})
Aresult
11
00
3044 32 my $Rule = $Event->{recurrenceRule};
3045 32 ▶ $Rule = undef unless ref $Rule eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Rule eq "HASH" 1 31 32
3046 32 ▶ my $limit = defined $before ? $before : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $before ? : 2 30 32
3047 5134 ▶ my $take = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
3048 5134 my $rid = shift;
3049 5134 ▶ return 1 if $excluded{$rid} or !$inRange->($rid);
Branch: 1 branch
BranchTrueFalseTotal
if $excluded{$rid} or not &$inRange($rid) 7 5127 5134
Condition100%3/3
$excluded{$rid} or not &$inRange($rid)
l!l&&r!l&&!r
165127
MC/DC100%2/2
$excluded{$rid} or not &$inRange($rid)
$excluded{$rid} not &$inRange($rid)
Truth table100%3/3
A or not(B)
A= $excluded{$rid}B= not &$inRange($rid)
ABresult
1X1
011
000
3050 5127 push @found, $rid;
3051 5127 return @found < $max;
3052 32 };
3053 32 ▶ if ($Rule) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Rule) { } 31 1 32
elsif (not defined $before or $start lt $before) { } 1 0 1
3054 31 _expandRule($Rule, $start, $limit, $take, $after);
3055 }
3056 ▶ elsif (!defined $before or $start lt $before) {
Condition33%1/3
not defined $before or $start lt $before
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $before or $start lt $before
not defined $before $start lt $before
Truth table33%1/3
not(A) or B
A= not defined $beforeB= $start lt $before
ABresult
1X1
011
000
3057 1 $take->($start);
3058 }
3059 }
3060  
3061 32 my %seen;
3062 32 ▶ my @all = sort grep { !$seen{$_}++ } @found, grep { !$excluded{$_} and $inRange->($_) } @added;
Condition33%1/3
!$excluded{$_} && &$inRange($_)
!ll&&!rl&&r
005
MC/DC0%0/2
!$excluded{$_} && &$inRange($_)
!$excluded{$_} &$inRange($_)
Truth table33%1/3
not(A) && B
A= !$excluded{$_}B= &$inRange($_)
ABresult
0X0
100
111
3063 32 ▶ splice @all, $max if @all > $max;
Branch: 1 branch
BranchTrueFalseTotal
if @all > $max 0 32 32
3064 32 return @all;
3065 }
3066  
3067 # A LocalDateTime in the canonical form of override keys, or undef.
3068 # A trailing Z or fraction is dropped; a bare date is its midnight.
3069 51 ▶sub _localDateTime {
Subroutine _localDateTime: called CC=5 SCAR=18.1
3070 51 my $value = shift;
3071 51 ▶ return undef unless defined $value and not ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 51 51
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0051
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
3072 51 ▶ return "$1T00:00:00" if $value =~ /^(\d{4}-\d\d-\d\d)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(\d{4}-\d\d-\d\d)$/ 1 50 51
3073 50 ▶ return "$1T$2" if $value =~ /^(\d{4}-\d\d-\d\d)T(\d\d:\d\d:\d\d)(?:\.\d+)?Z?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(\d{4}-\d\d-\d\d)T(\d\d:\d\d:\d\d)(?:\.\d+)?Z?$/i 50 0 50
3074 0 return undef;
3075 }
3076  
3077 # --- recurrence rule expansion (jscalendarbis-22 3.3.3.1) ---------------
3078 #
3079 # Days are counted from 1970-01-01 (day 0, a Thursday); weekdays are
3080 # 0 (mo) to 6 (su). Everything is local time: recurrence ids are.
3081  
3082 18 my %DayNum = (mo => 0, tu => 1, we => 2, th => 3, fr => 4, sa => 5, su => 6);
3083  
3084 13459 ▶sub _isLeap { my $y = shift; return ($y % 4 == 0 && $y % 100 != 0) || $y % 400 == 0 }
Subroutine _isLeap: called CC=3 SCAR=11.0
Condition100%6/6
$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0
l!l&&r!l&&!r
290144710111
$y % 4 == 0 and $y % 100 != 0
!ll&&!rl&&r
100275312901
MC/DC100%3/3
$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0
$y % 4 == 0 $y % 100 != 0 $y % 400 == 0
Truth table80%4/5
A and B || C
A= $y % 4 == 0B= $y % 100 != 0C= $y % 400 == 0
ABCresult
11X1
0X11
1011
0X00
1000
3085  
3086 12281 ▶sub _daysInMonth {
Subroutine _daysInMonth: called CC=3 SCAR=11.0
3087 12281 my ($y, $m) = @_;
3088 12281 ▶ return 29 if $m == 2 and _isLeap($y);
Branch: 1 branch
BranchTrueFalseTotal
if $m == 2 and _isLeap($y) 2930 9351 12281
Condition100%3/3
$m == 2 and _isLeap($y)
!ll&&!rl&&r
49188602930
MC/DC100%2/2
$m == 2 and _isLeap($y)
$m == 2 _isLeap($y)
Truth table100%3/3
A and B
A= $m == 2B= _isLeap($y)
ABresult
0X0
100
111
3089 9351 return (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$m - 1];
3090 }
3091  
3092 # days from civil and back (H. Hinnant's algorithms)
3093 10308 ▶sub _dayNumber {
Subroutine _dayNumber: called CC=4 SCAR=13.9
3094 10308 my ($y, $m, $d) = @_;
3095 10308 ▶ $y -= 1 if $m <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $m <= 2 7252 3056 10308
3096 10308 ▶ my $era = int(($y >= 0 ? $y : $y - 399) / 400);
Branch: 1 branch
BranchTrueFalseTotal
$y >= 0 ? : 10308 0 10308
3097 10308 my $yoe = $y - $era * 400;
3098 10308 ▶ my $doy = int((153 * ($m + ($m > 2 ? -3 : 9)) + 2) / 5) + $d - 1;
Branch: 1 branch
BranchTrueFalseTotal
$m > 2 ? : 3056 7252 10308
3099 10308 my $doe = $yoe * 365 + int($yoe / 4) - int($yoe / 100) + $doy;
3100 10308 return $era * 146097 + $doe - 719468;
3101 }
3102  
3103 179244 ▶sub _civil {
Subroutine _civil: called CC=4 SCAR=13.9
3104 179244 my $z = shift() + 719468;
3105 179244 ▶ my $era = int(($z >= 0 ? $z : $z - 146096) / 146097);
Branch: 1 branch
BranchTrueFalseTotal
$z >= 0 ? : 179244 0 179244
3106 179244 my $doe = $z - $era * 146097;
3107 179244 my $yoe = int(($doe - int($doe / 1460) + int($doe / 36524) - int($doe / 146096)) / 365);
3108 179244 my $y = $yoe + $era * 400;
3109 179244 my $doy = $doe - (365 * $yoe + int($yoe / 4) - int($yoe / 100));
3110 179244 my $mp = int((5 * $doy + 2) / 153);
3111 179244 my $d = $doy - int((153 * $mp + 2) / 5) + 1;
3112 179244 ▶ my $m = $mp + ($mp < 10 ? 3 : -9);
Branch: 1 branch
BranchTrueFalseTotal
$mp < 10 ? : 150431 28813 179244
3113 179244 ▶ return ($y + ($m <= 2 ? 1 : 0), $m, $d);
Branch: 1 branch
BranchTrueFalseTotal
$m <= 2 ? : 28813 150431 179244
3114 }
3115  
3116 7229 ▶sub _weekday { return (shift() + 3) % 7 } # day 0 was a Thursday
Subroutine _weekday: called CC=1 SCAR=0.0
3117  
3118 # The week number (and its year) of a day, weeks starting on $wkst, week
3119 # 1 being the first with four days in the year; and how many weeks that
3120 # year has.
3121 5114 ▶sub _weekNo {
Subroutine _weekNo: called CC=1 SCAR=0.0
3122 5114 my ($day, $wkst) = @_;
3123 5114 my $weekStart = $day - ((_weekday($day) - $wkst) % 7);
3124 5114 my ($wy) = _civil($weekStart + 3);
3125 5114 my $ordinal = $weekStart + 3 - _dayNumber($wy, 1, 1);
3126 5114 return (int($ordinal / 7) + 1, $wy);
3127 }
3128  
3129 2557 ▶sub _weeksInYear {
Subroutine _weeksInYear: called CC=1 SCAR=0.0
3130 2557 my ($y, $wkst) = @_;
3131 2557 my ($n) = _weekNo(_dayNumber($y, 12, 28), $wkst);
3132 2557 return $n;
3133 }
3134  
3135 270 ▶sub _list {
Subroutine _list: called CC=3 SCAR=11.0
3136 270 my $v = shift;
3137 270 ▶ return undef unless ref $v eq 'ARRAY' and @$v;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" and @$v 250 20 270
Condition66%2/3
ref $v eq "ARRAY" and @$v
!ll&&!rl&&r
250020
MC/DC50%1/2
ref $v eq "ARRAY" and @$v
ref $v eq "ARRAY" @$v
Truth table66%2/3
A and B
A= ref $v eq "ARRAY"B= @$v
ABresult
0X0
100
111
3138 20 return $v;
3139 }
3140  
3141 # Calls $take->($recurrenceId) for each occurrence of $Rule from $start
3142 # (the start itself first, always), in order, until it returns false,
3143 # the rule ends, an occurrence reaches $before, or 400 years pass
3144 # without one.
3145 31 ▶sub _expandRule {
Subroutine _expandRule: called CC=85 SCAR=46.5
3146 31 my ($Rule, $start, $before, $take, $after) = @_;
3147  
3148 31 ▶ my $freq = lc($Rule->{frequency} // '');
Condition50%1/2
$Rule->{"frequency"} // ""
l!l
310
MC/DC0%0/1
$Rule->{"frequency"} // ""
$Rule->{"frequency"}
Truth table50%1/2
A
A= $Rule->{"frequency"}
Aresult
11
00
3149 31 ▶ croak "recurrence frequency ($freq) is not valid" unless $ValidFrequency{$freq};
Branch: 1 branch
BranchTrueFalseTotal
unless $ValidFrequency{$freq} 0 31 31
3150 31 ▶ my $rscale = lc($Rule->{rscale} // 'gregorian');
Condition100%2/2
$Rule->{"rscale"} // "gregorian"
l!l
427
MC/DC100%1/1
$Rule->{"rscale"} // "gregorian"
$Rule->{"rscale"}
Truth table100%2/2
A
A= $Rule->{"rscale"}
Aresult
11
00
3151 31 ▶ croak "recurrence rscale $rscale is not supported" unless $rscale eq 'gregorian';
Branch: 1 branch
BranchTrueFalseTotal
unless $rscale eq "gregorian" 1 30 31
3152 30 ▶ my $skip = lc($Rule->{skip} // 'omit');
Condition100%2/2
$Rule->{"skip"} // "omit"
l!l
327
MC/DC100%1/1
$Rule->{"skip"} // "omit"
$Rule->{"skip"}
Truth table100%2/2
A
A= $Rule->{"skip"}
Aresult
11
00
3153 30 ▶ my $interval = $Rule->{interval} // 1;
Condition100%2/2
$Rule->{"interval"} // 1
l!l
723
MC/DC100%1/1
$Rule->{"interval"} // 1
$Rule->{"interval"}
Truth table100%2/2
A
A= $Rule->{"interval"}
Aresult
11
00
3154 30 ▶ croak "recurrence interval ($interval) is not valid" unless $interval =~ /^\d+$/ and $interval >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $interval =~ /^\d+$/ and $interval >= 1 0 30 30
Condition33%1/3
$interval =~ /^\d+$/ and $interval >= 1
!ll&&!rl&&r
0030
MC/DC0%0/2
$interval =~ /^\d+$/ and $interval >= 1
$interval =~ /^\d+$/ $interval >= 1
Truth table33%1/3
A and B
A= $interval =~ /^\d+$/B= $interval >= 1
ABresult
0X0
100
111
3155 30 ▶ my $wkst = $DayNum{lc($Rule->{firstDayOfWeek} // 'mo')} // croak 'recurrence firstDayOfWeek is not valid';
Condition75%3/4
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")} // croak("recurrence firstDayOfWeek is not valid")
l!l
300
$Rule->{"firstDayOfWeek"} // "mo"
l!l
129
MC/DC0%0/1
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")} // croak("recurrence firstDayOfWeek is not valid")
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")}
MC/DC100%1/1
$Rule->{"firstDayOfWeek"} // "mo"
$Rule->{"firstDayOfWeek"}
Truth table50%1/2
A
A= $DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")}
Aresult
11
00
Truth table100%2/2
A
A= $Rule->{"firstDayOfWeek"}
Aresult
11
00
3156 30 my $count = $Rule->{count};
3157 30 ▶ croak "recurrence count ($count) is not valid" if defined $count and $count !~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $count and not $count =~ /^\d+$/ 0 30 30
Condition66%2/3
defined $count and not $count =~ /^\d+$/
!ll&&!rl&&r
7230
MC/DC0%0/2
defined $count and not $count =~ /^\d+$/
defined $count not $count =~ /^\d+$/
Truth table66%2/3
A and not(B)
A= defined $countB= not $count =~ /^\d+$/
ABresult
0X0
100
111
3158 30 my $until;
3159 30 ▶ if (defined $Rule->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Rule->{"until"}) 2 28 30
3160 2 ▶ $until = _localDateTime($Rule->{until}) // croak "recurrence until ($Rule->{until}) is not valid";
Condition50%1/2
_localDateTime($Rule->{"until"}) // croak(qq[recurrence until ($Rule->{"until"}) is not valid])
l!l
20
MC/DC0%0/1
_localDateTime($Rule->{"until"}) // croak(qq[recurrence until ($Rule->{"until"}) is not valid])
_localDateTime($Rule->{"until"})
Truth table50%1/2
A
A= _localDateTime($Rule->{"until"})
Aresult
11
00
3161 }
3162  
3163 30 my ($sy, $sm, $sd, $sH, $sM, $sS) = $start =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/;
3164 30 $_ += 0 for $sy, $sm, $sd, $sH, $sM, $sS;
3165 30 my $startDay = _dayNumber($sy, $sm, $sd);
3166  
3167 # the rule's parts, numbers checked, and those implied by the start
3168 30 my %by;
3169 30 foreach my $name (qw(byMonthDay byYearDay byWeekNo byHour byMinute bySecond bySetPosition)) {
3170 210 ▶ my $list = _list($Rule->{$name}) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $list = _list($Rule->{$name}) or next 10 200 210
3171 10 ▶ $by{$name} = [ map { croak "recurrence $name ($_) is not valid" unless defined $_ and /^[-+]?\d+$/; 0 + $_ } @$list ];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and /^[-+]?\d+$/ 0 15 15
Condition33%1/3
defined $_ and /^[-+]?\d+$/
!ll&&!rl&&r
0015
MC/DC0%0/2
defined $_ and /^[-+]?\d+$/
defined $_ /^[-+]?\d+$/
Truth table33%1/3
A and B
A= defined $_B= /^[-+]?\d+$/
ABresult
0X0
100
111
3172 }
3173 30 my %range = (byHour => [0, 23], byMinute => [0, 59], bySecond => [0, 60]);
3174 30 foreach my $name (keys %range) {
3175 90 ▶ next unless $by{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $by{$name} 87 3 90
3176 croak "recurrence $name is out of range"
3177 3 ▶ if grep { $_ < $range{$name}[0] or $_ > $range{$name}[1] } @{$by{$name}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ < $range{$name}[0] or $_ > $range{$name}[1];} @{$by{$name};} 0 3 3
Condition33%1/3
$_ < $range{$name}[0] || $_ > $range{$name}[1]
l!l&&r!l&&!r
006
MC/DC0%0/2
$_ < $range{$name}[0] || $_ > $range{$name}[1]
$_ < $range{$name}[0] $_ > $range{$name}[1]
Truth table33%1/3
A || B
A= $_ < $range{$name}[0]B= $_ > $range{$name}[1]
ABresult
1X1
011
000
3178 }
3179 30 ▶ if (my $list = _list($Rule->{byMonth})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = _list($Rule->{"byMonth"})) 2 28 30
3180 # a leap month ("5L") never matches in the Gregorian calendar
3181 2 ▶ $by{byMonth} = { map { (defined $_ and /^(\d+)$/) ? (0 + $1 => 1) : () } @$list };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && /^(\d+)$/ ? : 2 0 2
Condition33%1/3
defined $_ and /^(\d+)$/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ and /^(\d+)$/
defined $_ /^(\d+)$/
Truth table33%1/3
A and B
A= defined $_B= /^(\d+)$/
ABresult
0X0
100
111
3182 }
3183 30 ▶ if (my $list = _list($Rule->{byDay})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = _list($Rule->{"byDay"})) 8 22 30
3184 $by{byDay} = [ map {
3185 8 ▶ croak 'recurrence byDay is not valid' unless ref $_ eq 'HASH' and defined $_->{day} and exists $DayNum{lc $_->{day}};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}} 0 15 15
Condition33%2/6
ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}}
!ll&&!rl&&r
0015
ref $_ eq "HASH" and defined $_->{"day"}
!ll&&!rl&&r
0015
MC/DC0%0/3
ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}}
ref $_ eq "HASH" defined $_->{"day"} exists $DayNum{lc $_->{"day"}}
Truth table25%1/4
A and B and C
A= ref $_ eq "HASH"B= defined $_->{"day"}C= exists $DayNum{lc $_->{"day"}}
ABCresult
0XX0
10X0
1100
1111
3186 15 ▶ [ $DayNum{lc $_->{day}}, $_->{nthOfPeriod} ? 0 + $_->{nthOfPeriod} : 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$_->{'nthOfPeriod'} ? : 4 11 15
3187 } @$list ];
3188 }
3189 30 my $startDow = _weekday($startDay);
3190 30 ▶ $by{bySecond} //= [$sS] unless $freq eq 'secondly';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" 29 1 30
Condition50%1/2
$by{"bySecond"} //= [$sS]
l!l
029
MC/DC0%0/1
$by{"bySecond"} //= [$sS]
$by{"bySecond"}
Truth table50%1/2
A
A= $by{"bySecond"}
Aresult
11
00
3191 30 ▶ $by{byMinute} //= [$sM] unless $freq eq 'secondly' or $freq eq 'minutely';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" or $freq eq "minutely" 28 2 30
Condition100%5/5
$freq eq "secondly" or $freq eq "minutely"
l!l&&r!l&&!r
1128
$by{"byMinute"} //= [$sM]
l!l
127
MC/DC100%2/2
$freq eq "secondly" or $freq eq "minutely"
$freq eq "secondly" $freq eq "minutely"
MC/DC100%1/1
$by{"byMinute"} //= [$sM]
$by{"byMinute"}
Truth table100%3/3
A or B
A= $freq eq "secondly"B= $freq eq "minutely"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $by{"byMinute"}
Aresult
11
00
3192 30 ▶ $by{byHour} //= [$sH] unless $freq eq 'secondly' or $freq eq 'minutely' or $freq eq 'hourly';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly" 26 4 30
Condition100%8/8
$freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly"
l!l&&r!l&&!r
2226
$freq eq "secondly" or $freq eq "minutely"
l!l&&r!l&&!r
1128
$by{"byHour"} //= [$sH]
l!l
125
MC/DC100%3/3
$freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly"
$freq eq "secondly" $freq eq "minutely" $freq eq "hourly"
MC/DC100%1/1
$by{"byHour"} //= [$sH]
$by{"byHour"}
Truth table100%4/4
A or B or C
A= $freq eq "secondly"B= $freq eq "minutely"C= $freq eq "hourly"
ABCresult
1XX1
01X1
0011
0000
Truth table100%2/2
A
A= $by{"byHour"}
Aresult
11
00
3193 30 ▶ if ($freq eq 'weekly' and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "weekly" and not $by{"byDay"}) 1 29 30
Condition100%3/3
$freq eq "weekly" and not $by{"byDay"}
!ll&&!rl&&r
2721
MC/DC100%2/2
$freq eq "weekly" and not $by{"byDay"}
$freq eq "weekly" not $by{"byDay"}
Truth table100%3/3
A and not(B)
A= $freq eq "weekly"B= not $by{"byDay"}
ABresult
0X0
100
111
3194 1 $by{byDay} = [[$startDow, 0]];
3195 }
3196 30 ▶ if ($freq eq 'monthly' and !$by{byDay} and !$by{byMonthDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}) 2 28 30
Condition100%6/6
$freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}
!ll&&!rl&&r
2622
$freq eq "monthly" and not $by{"byDay"}
!ll&&!rl&&r
2334
MC/DC100%3/3
$freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}
$freq eq "monthly" not $by{"byDay"} not $by{"byMonthDay"}
Truth table100%4/4
A and not(B) and not(C)
A= $freq eq "monthly"B= not $by{"byDay"}C= not $by{"byMonthDay"}
ABCresult
0XX0
10X0
1100
1111
3197 2 $by{byMonthDay} = [$sd];
3198 }
3199 30 ▶ if ($freq eq 'yearly' and !$by{byYearDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "yearly" and not $by{"byYearDay"}) 7 23 30
Condition100%3/3
$freq eq "yearly" and not $by{"byYearDay"}
!ll&&!rl&&r
2217
MC/DC100%2/2
$freq eq "yearly" and not $by{"byYearDay"}
$freq eq "yearly" not $by{"byYearDay"}
Truth table100%3/3
A and not(B)
A= $freq eq "yearly"B= not $by{"byYearDay"}
ABresult
0X0
100
111
3200 7 ▶ if (!$by{byMonth} and !$by{byWeekNo} and ($by{byMonthDay} or !$by{byDay})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}) 2 5 7
Condition88%8/9
not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}
!ll&&!rl&&r
412
$by{'byMonth'} || $by{'byWeekNo'}
l!l&&r!l&&!r
223
$by{"byMonthDay"} or not $by{"byDay"}
l!l&&r!l&&!r
021
MC/DC75%3/4
not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}
$by{'byMonth'} $by{'byWeekNo'} $by{"byMonthDay"} not $by{"byDay"}
Truth table80%4/5
not(A || B) and C or not(D)
A= $by{'byMonth'}B= $by{'byWeekNo'}C= $by{"byMonthDay"}D= not $by{"byDay"}
ABCDresult
1XXX0
01XX0
00000
001X1
00011
3201 2 $by{byMonth} = { $sm => 1 };
3202 }
3203 7 ▶ if (!$by{byMonthDay} and !$by{byWeekNo} and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}) 2 5 7
Condition100%6/6
$by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}
l!l&&r!l&&!r
322
$by{"byMonthDay"} or $by{"byWeekNo"}
l!l&&r!l&&!r
124
MC/DC100%3/3
$by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}
$by{"byMonthDay"} $by{"byWeekNo"} $by{"byDay"}
Truth table100%4/4
A or B or C
A= $by{"byMonthDay"}B= $by{"byWeekNo"}C= $by{"byDay"}
ABCresult
1XX1
01X1
0011
0000
3204 2 $by{byMonthDay} = [$sd];
3205 }
3206 7 ▶ if ($by{byWeekNo} and !$by{byMonthDay} and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}) 1 6 7
Condition83%5/6
$by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}
!ll&&!rl&&r
511
$by{"byWeekNo"} and not $by{"byMonthDay"}
!ll&&!rl&&r
502
MC/DC66%2/3
$by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}
$by{"byWeekNo"} not $by{"byMonthDay"} not $by{"byDay"}
Truth table75%3/4
A and not(B) and not(C)
A= $by{"byWeekNo"}B= not $by{"byMonthDay"}C= not $by{"byDay"}
ABCresult
0XX0
10X0
1100
1111
3207 1 $by{byDay} = [[$startDow, 0]];
3208 }
3209 }
3210 30 ▶ my $nthInYear = ($freq eq 'yearly' and !$by{byMonth});
Condition100%3/3
$freq eq 'yearly' && !$by{'byMonth'}
!ll&&!rl&&r
2244
MC/DC100%2/2
$freq eq 'yearly' && !$by{'byMonth'}
$freq eq 'yearly' !$by{'byMonth'}
Truth table100%3/3
A && not(B)
A= $freq eq 'yearly'B= !$by{'byMonth'}
ABresult
0X0
100
111
3211 30 ▶ my %inList = map { $_ => { map { $_ => 1 } @{$by{$_} || []} } } qw(byHour byMinute bySecond);
Condition100%2/2
$by{$_} || []
l!l
846
MC/DC100%1/1
$by{$_} || []
$by{$_}
Truth table100%2/2
A
A= $by{$_}
Aresult
11
00
3212  
3213 # does a (valid) day pass byMonth, byWeekNo, byYearDay, byMonthDay?
3214 163813 ▶ my $dayMatchesUpToMonthDay = sub {
Subroutine __ANON__: called CC=14 SCAR=26.4
3215 163813 my ($day, $y, $m, $d, $skipMonthDay) = @_;
3216 163813 ▶ return 0 if $by{byMonth} and !$by{byMonth}{$m};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byMonth"} and not $by{"byMonth"}{$m} 140523 23290 163813
Condition100%3/3
$by{"byMonth"} and not $by{"byMonth"}{$m}
!ll&&!rl&&r
1150611784140523
MC/DC100%2/2
$by{"byMonth"} and not $by{"byMonth"}{$m}
$by{"byMonth"} not $by{"byMonth"}{$m}
Truth table100%3/3
A and not(B)
A= $by{"byMonth"}B= not $by{"byMonth"}{$m}
ABresult
0X0
100
111
3217 23290 ▶ if ($by{byWeekNo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byWeekNo"}) 2557 20733 23290
3218 2557 my ($wn, $wy) = _weekNo($day, $wkst);
3219 2557 my $total = _weeksInYear($wy, $wkst);
3220 2557 ▶ return 0 unless grep { $_ > 0 ? $_ == $wn : $total + 1 + $_ == $wn } @{$by{byWeekNo}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $wn : $total + 1 + $_ == $wn;} @{$by{"byWeekNo"};} 2508 49 2557
$_ > 0 ? : 1461 1096 2557
3221 }
3222 20782 ▶ if ($by{byYearDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byYearDay"}) 1461 19321 20782
3223 1461 my $yd = $day - _dayNumber($y, 1, 1) + 1;
3224 1461 ▶ my $diy = _isLeap($y) ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
_isLeap($y) ? : 366 1095 1461
3225 1461 ▶ return 0 unless grep { $_ > 0 ? $_ == $yd : $diy + 1 + $_ == $yd } @{$by{byYearDay}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $yd : $diy + 1 + $_ == $yd;} @{$by{"byYearDay"};} 1449 12 1461
$_ > 0 ? : 4383 0 4383
3226 }
3227 19333 ▶ if ($by{byMonthDay} and !$skipMonthDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byMonthDay"} and not $skipMonthDay) 12176 7157 19333
Condition100%3/3
$by{"byMonthDay"} and not $skipMonthDay
!ll&&!rl&&r
7150712176
MC/DC100%2/2
$by{"byMonthDay"} and not $skipMonthDay
$by{"byMonthDay"} not $skipMonthDay
Truth table100%3/3
A and not(B)
A= $by{"byMonthDay"}B= not $skipMonthDay
ABresult
0X0
100
111
3228 12176 my $dim = _daysInMonth($y, $m);
3229 12176 ▶ return 0 unless grep { $_ > 0 ? $_ == $d : $dim + 1 + $_ == $d } @{$by{byMonthDay}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $d : $dim + 1 + $_ == $d;} @{$by{"byMonthDay"};} 12160 16 12176
$_ > 0 ? : 11964 212 12176
3230 }
3231 7173 return 1;
3232 30 };
3233 7180 ▶ my $dayMatchesByDay = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
3234 7180 my ($day, $y, $m, $d) = @_;
3235 7180 ▶ return 1 unless $by{byDay};
Branch: 1 branch
BranchTrueFalseTotal
unless $by{"byDay"} 5106 2074 7180
3236 2074 my $dow = _weekday($day);
3237 2074 foreach my $bd (@{$by{byDay}}) {
3238 2462 ▶ next unless $bd->[0] == $dow;
Branch: 1 branch
BranchTrueFalseTotal
unless $bd->[0] == $dow 2095 367 2462
3239 367 ▶ return 1 unless $bd->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $bd->[1] 97 270 367
3240 270 ▶ my ($pos, $len) = $nthInYear
Branch: 2 branches
BranchTrueFalseTotal
$nthInYear ? : 208 62 270
_isLeap($y) ? : 52 156 208
3241 ? ($day - _dayNumber($y, 1, 1) + 1, _isLeap($y) ? 366 : 365)
3242 : ($d, _daysInMonth($y, $m));
3243 270 ▶ my $n = $bd->[1] > 0 ? int(($pos - 1) / 7) + 1 : -(int(($len - $pos) / 7) + 1);
Branch: 1 branch
BranchTrueFalseTotal
$bd->[1] > 0 ? : 256 14 270
3244 270 ▶ return 1 if $n == $bd->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $n == $bd->[1] 19 251 270
3245 }
3246 1958 return 0;
3247 30 };
3248  
3249 # the candidate days of a year or month when skip moves invalid dates
3250 # (jscalendarbis-22 3.3.3.1, step 2): byMonthDay is applied to every
3251 # month as if it had 31 days, and an invalid date moves
3252 30 ▶ my $skipping = ($skip ne 'omit' and $by{byMonthDay} and ($freq eq 'yearly' or $freq eq 'monthly'));
Condition66%6/9
$skip ne 'omit' && $by{'byMonthDay'} && ($freq eq 'yearly' || $freq eq 'monthly')
!ll&&!rl&&r
2703
$skip ne "omit" and $by{"byMonthDay"}
!ll&&!rl&&r
2703
$freq eq "yearly" or $freq eq "monthly"
l!l&&r!l&&!r
120
MC/DC25%1/4
$skip ne 'omit' && $by{'byMonthDay'} && ($freq eq 'yearly' || $freq eq 'monthly')
$skip ne "omit" $by{"byMonthDay"} $freq eq "yearly" $freq eq "monthly"
Truth table60%3/5
A and B && C or D
A= $skip ne "omit"B= $by{"byMonthDay"}C= $freq eq "yearly"D= $freq eq "monthly"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
3253 14 ▶ my $skipDays = sub {
Subroutine __ANON__: called CC=15 SCAR=29.9
3254 14 my ($y, @months) = @_;
3255 14 my %days;
3256 14 foreach my $m (@months) {
3257 58 ▶ next if $by{byMonth} and !$by{byMonth}{$m};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byMonth"} and not $by{"byMonth"}{$m} 44 14 58
Condition100%3/3
$by{"byMonth"} and not $by{"byMonth"}{$m}
!ll&&!rl&&r
10444
MC/DC100%2/2
$by{"byMonth"} and not $by{"byMonth"}{$m}
$by{"byMonth"} not $by{"byMonth"}{$m}
Truth table100%3/3
A and not(B)
A= $by{"byMonth"}B= not $by{"byMonth"}{$m}
ABresult
0X0
100
111
3258 14 my $dim = _daysInMonth($y, $m);
3259 14 foreach my $v (@{$by{byMonthDay}}) {
3260 14 my $day;
3261 14 ▶ if ($v > 0 and $v <= $dim) { $day = _dayNumber($y, $m, $v) }
Branch: 2 branches
BranchTrueFalseTotal
if ($v > 0 and $v <= $dim) { } 7 7 14
elsif ($v < 0 and $dim + 1 + $v >= 1) { } 0 7 7
Condition66%2/3
$v > 0 and $v <= $dim
!ll&&!rl&&r
077
MC/DC50%1/2
$v > 0 and $v <= $dim
$v > 0 $v <= $dim
Truth table66%2/3
A and B
A= $v > 0B= $v <= $dim
ABresult
0X0
100
111
3262 0 ▶ elsif ($v < 0 and $dim + 1 + $v >= 1) { $day = _dayNumber($y, $m, $dim + 1 + $v) }
Condition33%1/3
$v < 0 and $dim + 1 + $v >= 1
!ll&&!rl&&r
700
MC/DC0%0/2
$v < 0 and $dim + 1 + $v >= 1
$v < 0 $dim + 1 + $v >= 1
Truth table33%1/3
A and B
A= $v < 0B= $dim + 1 + $v >= 1
ABresult
0X0
100
111
3263 else {
3264 # invalid: byWeekNo and byYearDay never match it
3265 7 ▶ next if $by{byWeekNo} or $by{byYearDay};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byWeekNo"} or $by{"byYearDay"} 0 7 7
Condition33%1/3
$by{"byWeekNo"} or $by{"byYearDay"}
l!l&&r!l&&!r
007
MC/DC0%0/2
$by{"byWeekNo"} or $by{"byYearDay"}
$by{"byWeekNo"} $by{"byYearDay"}
Truth table33%1/3
A or B
A= $by{"byWeekNo"}B= $by{"byYearDay"}
ABresult
1X1
011
000
3266 7 ▶ if ($v > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > 0) { } 7 0 7
3267 7 ▶ $day = $skip eq 'forward' ? _dayNumber($y, $m, $dim) + 1 : _dayNumber($y, $m, $dim);
Branch: 1 branch
BranchTrueFalseTotal
$skip eq 'forward' ? : 5 2 7
3268 }
3269 else {
3270 0 ▶ $day = $skip eq 'forward' ? _dayNumber($y, $m, 1) : _dayNumber($y, $m, 1) - 1;
Branch: 1 branch
BranchTrueFalseTotal
$skip eq 'forward' ? : 0 0 0
3271 }
3272 7 $days{$day} = 1;
3273 7 next;
3274 }
3275 7 my (undef, undef, $d) = _civil($day);
3276 7 ▶ $days{$day} = 1 if $dayMatchesUpToMonthDay->($day, $y, $m, $d, 1);
Branch: 1 branch
BranchTrueFalseTotal
if &$dayMatchesUpToMonthDay($day, $y, $m, $d, 1) 7 0 7
3277 }
3278 }
3279 0 return grep { $dayMatchesByDay->($_, _civil($_)) } sort { $a <=> $b } keys %days;
3280 30 };
3281  
3282 # the days of a period that pass every date filter
3283 5536 ▶ my $daysOf = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
3284 5536 my ($first, $last) = @_;
3285 5536 my @days;
3286 5536 for my $day ($first .. $last) {
3287 163806 my ($y, $m, $d) = _civil($day);
3288 163806 ▶ push @days, $day if $dayMatchesUpToMonthDay->($day, $y, $m, $d) and $dayMatchesByDay->($day, $y, $m, $d);
Branch: 1 branch
BranchTrueFalseTotal
if &$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d) 5208 158598 163806
Condition100%3/3
&$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d)
!ll&&!rl&&r
15664019585208
MC/DC100%2/2
&$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d)
&$dayMatchesUpToMonthDay($day, $y, $m, $d) &$dayMatchesByDay($day, $y, $m, $d)
Truth table100%3/3
A and B
A= &$dayMatchesUpToMonthDay($day, $y, $m, $d)B= &$dayMatchesByDay($day, $y, $m, $d)
ABresult
0X0
100
111
3289 }
3290 5536 return @days;
3291 30 };
3292  
3293 30 my @hours = sort { $a <=> $b } keys %{$inList{byHour}};
3294 30 my @minutes = sort { $a <=> $b } keys %{$inList{byMinute}};
3295 0 my @seconds = sort { $a <=> $b } keys %{$inList{bySecond}};
3296 10303 ▶ my $fmt = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3297 10303 my ($day, $H, $M, $S) = @_;
3298 10303 my ($y, $m, $d) = _civil($day);
3299 10303 return sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $y, $m, $d, $H, $M, $S);
3300 30 };
3301  
3302 # the candidates of period $n, in order
3303 30 my $periodStart; # the first date-time of the period, as a string
3304 my $noDays; # no day of the period passed the date filters
3305 5550 ▶ my $candidates = sub {
Subroutine __ANON__: called CC=26 SCAR=33.4
3306 5550 my $n = shift;
3307 5550 my (@days, @H, @M, @S);
3308 5550 @H = @hours; @M = @minutes; @S = @seconds;
3309 5550 ▶ if ($freq eq 'yearly') {
Branch: 4 branches
BranchTrueFalseTotal
if ($freq eq 'yearly') { } 436 5114 5550
elsif ($freq eq 'monthly') { } 39 5075 5114
elsif ($freq eq 'weekly') { } 11 5064 5075
elsif ($freq eq 'daily') { } 5039 25 5064
3310 436 my $y = $sy + $n * $interval;
3311 436 $periodStart = sprintf('%04d-01-01T00:00:00', $y);
3312 436 ▶ @days = $skipping ? $skipDays->($y, 1 .. 12)
Branch: 1 branch
BranchTrueFalseTotal
$skipping ? : 4 432 436
3313 : $daysOf->(_dayNumber($y, 1, 1), _dayNumber($y, 12, 31));
3314 }
3315 elsif ($freq eq 'monthly') {
3316 39 my $mi = ($sy * 12 + $sm - 1) + $n * $interval;
3317 39 my ($y, $m) = (int($mi / 12), $mi % 12 + 1);
3318 39 $periodStart = sprintf('%04d-%02d-01T00:00:00', $y, $m);
3319 39 ▶ @days = $skipping ? $skipDays->($y, $m)
Branch: 1 branch
BranchTrueFalseTotal
$skipping ? : 10 29 39
3320 : $daysOf->(_dayNumber($y, $m, 1), _dayNumber($y, $m, _daysInMonth($y, $m)));
3321 }
3322 elsif ($freq eq 'weekly') {
3323 11 my $first = $startDay - ((_weekday($startDay) - $wkst) % 7) + 7 * $n * $interval;
3324 11 $periodStart = $fmt->($first, 0, 0, 0);
3325 11 @days = $daysOf->($first, $first + 6);
3326 }
3327 elsif ($freq eq 'daily') {
3328 5039 my $day = $startDay + $n * $interval;
3329 5039 $periodStart = $fmt->($day, 0, 0, 0);
3330 5039 @days = $daysOf->($day, $day);
3331 }
3332 else {
3333 25 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3334 25 my $t = (($startDay * 24 + $sH) * 60 + $sM) * 60 + $sS;
3335 25 $t -= $t % $unit;
3336 25 $t += $n * $interval * $unit;
3337 25 my $day = int($t / 86400);
3338 25 ▶ $day-- if $t < 0 and $t % 86400;
Branch: 1 branch
BranchTrueFalseTotal
if $t < 0 and $t % 86400 0 25 25
Condition33%1/3
$t < 0 and $t % 86400
!ll&&!rl&&r
2500
MC/DC0%0/2
$t < 0 and $t % 86400
$t < 0 $t % 86400
Truth table33%1/3
A and B
A= $t < 0B= $t % 86400
ABresult
0X0
100
111
3339 25 my $secs = $t - $day * 86400;
3340 25 my ($H, $M, $S) = (int($secs / 3600), int(($secs % 3600) / 60), $secs % 60);
3341 25 ▶ $periodStart = $fmt->($day, $H, $M, $freq eq 'secondly' ? $S : 0);
Branch: 1 branch
BranchTrueFalseTotal
$freq eq 'secondly' ? : 10 15 25
3342 25 @days = $daysOf->($day, $day);
3343 25 ▶ @H = $inList{byHour}{$H} || !%{$inList{byHour}} ? ($H) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'byHour'}{$H} || !%{$inList{'byHour'};} ? : 25 0 25
Condition66%2/3
$inList{"byHour"}{$H} or not %{$inList{"byHour"};}
l!l&&r!l&&!r
5200
MC/DC0%0/2
$inList{"byHour"}{$H} or not %{$inList{"byHour"};}
$inList{"byHour"}{$H} not %{$inList{"byHour"};}
Truth table66%2/3
A or not(B)
A= $inList{"byHour"}{$H}B= not %{$inList{"byHour"};}
ABresult
1X1
011
000
3344 25 ▶ if ($freq ne 'hourly') {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq ne "hourly") 15 10 25
3345 15 ▶ @M = $inList{byMinute}{$M} || !%{$inList{byMinute}} ? ($M) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'byMinute'}{$M} || !%{$inList{'byMinute'};} ? : 15 0 15
Condition33%1/3
$inList{"byMinute"}{$M} or not %{$inList{"byMinute"};}
l!l&&r!l&&!r
0150
MC/DC0%0/2
$inList{"byMinute"}{$M} or not %{$inList{"byMinute"};}
$inList{"byMinute"}{$M} not %{$inList{"byMinute"};}
Truth table33%1/3
A or not(B)
A= $inList{"byMinute"}{$M}B= not %{$inList{"byMinute"};}
ABresult
1X1
011
000
3346 }
3347 25 ▶ if ($freq eq 'secondly') {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "secondly") 10 15 25
3348 10 ▶ @S = $inList{bySecond}{$S} || !%{$inList{bySecond}} ? ($S) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'bySecond'}{$S} || !%{$inList{'bySecond'};} ? : 10 0 10
Condition33%1/3
$inList{"bySecond"}{$S} or not %{$inList{"bySecond"};}
l!l&&r!l&&!r
0100
MC/DC0%0/2
$inList{"bySecond"}{$S} or not %{$inList{"bySecond"};}
$inList{"bySecond"}{$S} not %{$inList{"bySecond"};}
Truth table33%1/3
A or not(B)
A= $inList{"bySecond"}{$S}B= not %{$inList{"bySecond"};}
ABresult
1X1
011
000
3349 }
3350 }
3351 5550 $noDays = !@days;
3352 5550 my @out;
3353 5550 foreach my $day (@days) {
3354 5222 foreach my $H (@H) {
3355 5224 foreach my $M (@M) {
3356 5228 push @out, map { $fmt->($day, $H, $M, $_) } @S;
3357 }
3358 }
3359 }
3360 5550 ▶ if ($by{bySetPosition}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"bySetPosition"}) 3 5547 5550
3361 3 my @keep;
3362 3 foreach my $p (@{$by{bySetPosition}}) {
3363 3 ▶ my $i = $p > 0 ? $p - 1 : @out + $p;
Branch: 1 branch
BranchTrueFalseTotal
$p > 0 ? : 0 3 3
3364 3 ▶ push @keep, $out[$i] if $i >= 0 and $i < @out;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= 0 and $i < @out 3 0 3
Condition33%1/3
$i >= 0 and $i < @out
!ll&&!rl&&r
003
MC/DC0%0/2
$i >= 0 and $i < @out
$i >= 0 $i < @out
Truth table33%1/3
A and B
A= $i >= 0B= $i < @out
ABresult
0X0
100
111
3365 }
3366 3 my %u;
3367 3 @out = sort grep { !$u{$_}++ } @keep;
3368 }
3369 5550 return @out;
3370 30 };
3371  
3372 30 my $produced = 0;
3373 30 my %seen;
3374 5182 ▶ my $emit = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
3375 5182 my $rid = shift;
3376 5182 ▶ return 1 if $seen{$rid}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$rid}++ 25 5157 5182
3377 5157 ▶ return 0 if defined $until and $rid gt $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $rid gt $until 0 5157 5157
Condition66%2/3
defined $until and $rid gt $until
!ll&&!rl&&r
515070
MC/DC0%0/2
defined $until and $rid gt $until
defined $until $rid gt $until
Truth table66%2/3
A and B
A= defined $untilB= $rid gt $until
ABresult
0X0
100
111
3378 5157 ▶ return 0 if defined $before and $rid ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $rid ge $before 1 5156 5157
Condition100%3/3
defined $before and $rid ge $before
!ll&&!rl&&r
5145111
MC/DC100%2/2
defined $before and $rid ge $before
defined $before $rid ge $before
Truth table100%3/3
A and B
A= defined $beforeB= $rid ge $before
ABresult
0X0
100
111
3379 5156 ▶ return 0 if defined $count and $produced >= $count;
Branch: 1 branch
BranchTrueFalseTotal
if defined $count and $produced >= $count 23 5133 5156
Condition100%3/3
defined $count and $produced >= $count
!ll&&!rl&&r
502910423
MC/DC100%2/2
defined $count and $produced >= $count
defined $count $produced >= $count
Truth table100%3/3
A and B
A= defined $countB= $produced >= $count
ABresult
0X0
100
111
3380 5133 $produced++;
3381 5133 ▶ return $take->($rid) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$take($rid) ? : 5131 2 5133
3382 30 };
3383  
3384 # the start is always the first occurrence
3385 30 ▶ return unless $emit->($start);
Branch: 1 branch
BranchTrueFalseTotal
unless &$emit($start) 0 30 30
3386  
3387 # how many periods may pass without an occurrence: 400 years' worth
3388 my $idle = { yearly => 400, monthly => 4800, weekly => 20871, daily => 146097,
3389 30 hourly => 3506328, minutely => 210379680, secondly => 12622780800 }->{$freq};
3390 30 $idle = int($idle / $interval) + 1;
3391 30 my $sinceLast = 0;
3392 # a sub-daily rule on a day no date filter lets through skips the day
3393 30 ▶ my $subDaily = ($freq eq 'hourly' or $freq eq 'minutely' or $freq eq 'secondly');
Condition100%6/6
$freq eq 'hourly' || $freq eq 'minutely' || $freq eq 'secondly'
l!l&&r!l&&!r
3126
$freq eq "hourly" or $freq eq "minutely"
l!l&&r!l&&!r
2127
MC/DC100%3/3
$freq eq 'hourly' || $freq eq 'minutely' || $freq eq 'secondly'
$freq eq "hourly" $freq eq "minutely" $freq eq 'secondly'
Truth table100%4/4
A or B || C
A= $freq eq "hourly"B= $freq eq "minutely"C= $freq eq 'secondly'
ABCresult
1XX1
01X1
0011
0000
3394  
3395 # without a count, the periods before the one holding $after cannot
3396 # matter: start there (one early, for a date a skip moved forward)
3397 30 my $n0 = 0;
3398 30 ▶ if (defined $after and !defined $count and $after gt $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $after and not defined $count and $after gt $start) 2 28 30
Condition83%5/6
defined $after and not defined $count and $after gt $start
!ll&&!rl&&r
2802
defined $after and not defined $count
!ll&&!rl&&r
2712
MC/DC66%2/3
defined $after and not defined $count and $after gt $start
defined $after not defined $count $after gt $start
Truth table75%3/4
A and not(B) and C
A= defined $afterB= not defined $countC= $after gt $start
ABCresult
0XX0
10X0
1100
1111
3399 2 my ($ay, $am, $ad, $aH, $aM, $aS) = map { 0 + $_ } $after =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/;
3400 2 my $aDay = _dayNumber($ay, $am, $ad);
3401 2 my $steps;
3402 0 ▶ if ($freq eq 'yearly') { $steps = ($ay - $sy) }
Branch: 4 branches
BranchTrueFalseTotal
if ($freq eq 'yearly') { } 0 2 2
elsif ($freq eq 'monthly') { } 0 2 2
elsif ($freq eq 'weekly') { } 0 2 2
elsif ($freq eq 'daily') { } 1 1 2
3403 0 elsif ($freq eq 'monthly') { $steps = ($ay * 12 + $am) - ($sy * 12 + $sm) }
3404 0 elsif ($freq eq 'weekly') { $steps = int(($aDay - $startDay) / 7) }
3405 1 elsif ($freq eq 'daily') { $steps = $aDay - $startDay }
3406 else {
3407 1 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3408 1 my $secs = ((($aDay - $startDay) * 24 + $aH - $sH) * 60 + $aM - $sM) * 60 + $aS - $sS;
3409 1 $steps = int($secs / $unit);
3410 }
3411 2 $n0 = int($steps / $interval) - 1;
3412 2 ▶ $n0 = 0 if $n0 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n0 < 0 0 2 2
3413 }
3414  
3415 30 for (my $n = $n0; ; $n++) {
3416 5550 my @c = $candidates->($n);
3417 5550 ▶ return if defined $until and $periodStart gt $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $periodStart gt $until 2 5548 5550
Condition100%3/3
defined $until and $periodStart gt $until
!ll&&!rl&&r
554172
MC/DC100%2/2
defined $until and $periodStart gt $until
defined $until $periodStart gt $until
Truth table100%3/3
A and B
A= defined $untilB= $periodStart gt $until
ABresult
0X0
100
111
3418 5548 ▶ return if defined $before and $periodStart ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $periodStart ge $before 1 5547 5548
Condition100%3/3
defined $before and $periodStart ge $before
!ll&&!rl&&r
5537101
MC/DC100%2/2
defined $before and $periodStart ge $before
defined $before $periodStart ge $before
Truth table100%3/3
A and B
A= defined $beforeB= $periodStart ge $before
ABresult
0X0
100
111
3419 5547 my $any = 0;
3420 5547 foreach my $rid (@c) {
3421 5154 ▶ next if $rid lt $start;
Branch: 1 branch
BranchTrueFalseTotal
if $rid lt $start 2 5152 5154
3422 5152 $any = 1;
3423 5152 ▶ return unless $emit->($rid);
Branch: 1 branch
BranchTrueFalseTotal
unless &$emit($rid) 26 5126 5152
3424 }
3425 5521 ▶ if ($any) { $sinceLast = 0 }
Branch: 3 branches
BranchTrueFalseTotal
if ($any) { } 5106 415 5521
elsif (++$sinceLast > $idle) { } 1 414 415
elsif ($subDaily and $noDays) { } 0 828 828
3426 1 elsif (++$sinceLast > $idle) { return }
3427 ▶ elsif ($subDaily and $noDays) {
Condition33%1/3
$subDaily and $noDays
!ll&&!rl&&r
41400
MC/DC0%0/2
$subDaily and $noDays
$subDaily $noDays
Truth table33%1/3
A and B
A= $subDailyB= $noDays
ABresult
0X0
100
111
3428 # jump to the last period that starts on this day
3429 0 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3430 0 my ($H, $M, $S) = $periodStart =~ /T(\d\d):(\d\d):(\d\d)$/;
3431 0 my $left = int((86400 - ($H * 3600 + $M * 60 + $S) - 1) / ($unit * $interval));
3432 0 $n += $left;
3433 0 $sinceLast += $left;
3434 }
3435 }
3436 }
3437  
3438 # Order two instances by their RECURRENCE-ID (then DTSTART)
3439 5 ▶sub _compareInstances {
Subroutine _compareInstances: called CC=9 SCAR=34.1
3440 5 my ($A, $B) = @_;
3441 5 my ($ra, $rb) = map { $_->{_recurrenceObj} } $A, $B;
3442 5 ▶ if ($ra and $rb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ra and $rb) 5 0 5
Condition33%1/3
$ra and $rb
!ll&&!rl&&r
005
MC/DC0%0/2
$ra and $rb
$ra $rb
Truth table33%1/3
A and B
A= $raB= $rb
ABresult
0X0
100
111
3443 5 my $c = DateTime->compare($ra, $rb);
3444 5 ▶ return $c if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 5 0 5
3445 }
3446 0 ▶ return ($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{start} // '') cmp ($B->{start} // '');
Branch: 2 branches
BranchTrueFalseTotal
$ra ? : 0 0 0
$rb ? : 0 0 0
Condition0%0/7
($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{'start'} // '') cmp ($B->{'start'} // '')
l!l&&r!l&&!r
000
$A->{"start"} // ""
l!l
00
$B->{"start"} // ""
l!l
00
MC/DC0%0/2
($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{'start'} // '') cmp ($B->{'start'} // '')
($ra ? 0 : 1) <=> ($rb ? 0 : 1) $A->{"start"}
MC/DC0%0/1
$B->{"start"} // ""
$B->{"start"}
Truth table0%0/3
A || B
A= ($ra ? 0 : 1) <=> ($rb ? 0 : 1)B= $A->{"start"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $B->{"start"}
Aresult
11
00
3447 }
3448  
3449 119 ▶sub _quotekey {
Subroutine _quotekey: called CC=1 SCAR=0.0
3450 119 my $key = shift;
3451 119 $key =~ s/\~/~0/gs;
3452 119 $key =~ s/\//~1/gs;
3453 119 return $key;
3454 }
3455  
3456 249 ▶sub _unquotekey {
Subroutine _unquotekey: called CC=1 SCAR=0.0
3457 249 my $key = shift;
3458 249 $key =~ s/\~1/\//gs;
3459 249 $key =~ s/\~0/~/gs;
3460 249 return $key;
3461 }
3462  
3463 119 ▶sub _add_override {
Subroutine _add_override: called CC=8 SCAR=20.9
3464 119 my ($override, $prefix, $New, $Old) = @_;
3465  
3466 # basic case - it's not an object, so we just override
3467 119 ▶ if (ref($New) ne 'HASH' or ref($Old) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $New ne "HASH" or ref $Old ne "HASH") 92 27 119
Condition100%3/3
ref $New ne "HASH" or ref $Old ne "HASH"
l!l&&r!l&&!r
722027
MC/DC100%2/2
ref $New ne "HASH" or ref $Old ne "HASH"
ref $New ne "HASH" ref $Old ne "HASH"
Truth table100%3/3
A or B
A= ref $New ne "HASH"B= ref $Old ne "HASH"
ABresult
1X1
011
000
3468 92 $override->{$prefix} = $New;
3469 92 return;
3470 }
3471  
3472 # XXX - if too many, we could just abort...
3473 27 my %subover;
3474 27 my %oldkeys = map { $_ => 1 } keys %$Old;
3475 27 foreach my $Key (sort keys %$New) {
3476 80 delete $oldkeys{$Key};
3477 80 ▶ next if _safeeq($New->{$Key}, $Old->{$Key});
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($New->{$Key}, $Old->{$Key}) 53 27 80
3478 27 _add_override(\%subover, "$prefix/" . _quotekey($Key), $New->{$Key}, $Old->{$Key});
3479 }
3480 27 foreach my $Key (sort keys %oldkeys) {
3481 0 $subover{"$prefix/" . _quotekey($Key)} = $JSON::null;
3482 }
3483  
3484 # which one is better?
3485 27 ▶ if (length(encode_json($New)) < length(encode_json(\%subover))) {
Branch: 1 branch
BranchTrueFalseTotal
if (length &encode_json($New) < length &encode_json(\%subover)) { } 0 27 27
3486 0 $override->{$prefix} = $New; # cheaper to just encode the whole object
3487 }
3488 else {
3489 27 $override->{$_} = $subover{$_} for keys %subover;
3490 }
3491 }
3492  
3493 114 ▶sub _apply_patch {
Subroutine _apply_patch: called CC=5 SCAR=16.1
3494 114 my $path = shift;
3495 114 my $hash = shift;
3496 114 my $value = shift;
3497  
3498 114 ▶ return unless $path =~ s{^([^/]+)(/?)}{};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ s[^([^/]+)(/?)][] 0 114 114
3499 114 ▶ return unless ref($hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 0 114 114
3500 114 my $qkey = $1;
3501 114 my $slash = $2;
3502 114 my $key = _unquotekey($qkey);
3503 114 ▶ if ($slash) {
Branch: 2 branches
BranchTrueFalseTotal
if ($slash) { } 24 90 114
elsif (defined $value) { } 84 6 90
3504 24 _apply_patch($path, $hash->{$key}, $value);
3505 }
3506 elsif(defined $value) {
3507 84 $hash->{$key} = $value;
3508 }
3509 else {
3510 6 delete $hash->{$key};
3511 }
3512 }
3513  
3514 44 ▶sub _maximise {
Subroutine _maximise: called CC=4 SCAR=13.9
3515 44 my $Self = shift;
3516 44 my $Event = shift;
3517 44 my $Recurrence = shift;
3518 44 my $recurrenceId = shift;
3519  
3520 44 my $new = _deepcopy($Event);
3521 44 $new->{start} = $recurrenceId;
3522 44 delete $new->{recurrenceRule};
3523 44 delete $new->{recurrenceOverrides};
3524 44 delete $new->{SYNTHETIC_MASTER()};
3525  
3526 44 foreach my $path (sort keys %$Recurrence) {
3527 # overrides can't change the identity or type of the master event
3528 97 my ($first) = $path =~ m{^([^/]*)};
3529 97 my $key = _unquotekey($first);
3530 97 ▶ next if $MustBeTopLevel{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$key} 5 92 97
3531 92 ▶ next if $path =~ m{^participants/[^/]+/calendarAddress$};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[^participants/[^/]+/calendarAddress$] 2 90 92
3532 90 my $value = $Recurrence->{$path};
3533 90 _apply_patch($path, $new, $value);
3534 }
3535  
3536 44 return $new;
3537 }
3538  
3539 0 ▶sub _stripNonICal {
Subroutine _stripNonICal: not called CC=4 SCAR=30.0
3540 0 my $Self = shift;
3541 0 my $Event = shift;
3542  
3543 0 delete $Event->{alerts};
3544 0 delete $Event->{participants};
3545 0 delete $Event->{organizerCalendarAddress};
3546  
3547 0 ▶ foreach my $exception (values %{$Event->{recurrenceOverrides} || {}}) {
Condition0%0/2
$Event->{'recurrenceOverrides'} || {}
l!l
00
MC/DC0%0/1
$Event->{'recurrenceOverrides'} || {}
$Event->{'recurrenceOverrides'}
Truth table0%0/2
A
A= $Event->{'recurrenceOverrides'}
Aresult
11
00
3548 0 ▶ next unless ref($exception) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $exception eq "HASH" 0 0 0
3549 0 $Self->_stripNonICal($exception);
3550 }
3551 }
3552  
3553 1518 ▶sub _safeeq {
Subroutine _safeeq: called CC=1 SCAR=0.0
3554 1518 my ($a, $b) = @_;
3555 1518 my $json = JSON::XS->new->canonical;
3556 1518 return $json->encode([$a]) eq $json->encode([$b]);
3557 }
3558  
3559 44 ▶sub _deepcopy {
Subroutine _deepcopy: called CC=1 SCAR=0.0
3560 44 my $data = shift;
3561 44 my $json = JSON::XS->new->canonical;
3562 44 my $enc = $json->encode([$data]);
3563 44 my $copy = $json->decode($enc);
3564 44 return $copy->[0];
3565 }
3566  
3567  
3568 =head1 AUTHOR
3569  
3570 Bron Gondwana, C<< <brong at cpan.org> >>
3571  
3572 =head1 LICENSE AND COPYRIGHT
3573  
3574 Copyright 2019-2026 Fastmail Pty Ltd.
3575  
3576 This program is free software; you can redistribute it and/or modify it
3577 under the same terms as Perl itself; that is, either the GNU General
3578 Public License as published by the Free Software Foundation (version 1,
3579 or at your option any later version), or the Artistic License.
3580  
3581 See L<http://dev.perl.org/licenses/> and the LICENSE file included with
3582 this distribution for more information.
3583  
3584 =cut
3585  
3586 18 1; # End of Text::JSCalendar
« JSCalendar/TimeZones.pm ↑ Summary