blib/lib/DateTime/Event/Recurrence.pm

filter: Statementstmt 96.9% 416 / 429 Branchbran 84.5% 142 / 168 Conditioncond 77.4% 48 / 62 MC/DCmcdc 57.8% 22 / 38 Subroutinesub 96.4% 55 / 57 Podpod n/a totaltotal 90.5% 683 / 754 CC 121 SCAR 30.9
CC
121
Cov
92%
_create_recurrence
58.7
_get_previous
10.1
_get_next
10.0
CRAP 22.0
↑ Summary
1 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package DateTime::Set::ICal;
4  
5 15 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 # use Carp;
7  
8 # a "dt::set" with a symbolic string representation
9 15 @ISA = qw( DateTime::Set );
10  
11 107 ▶sub set_ical { # include list, exclude list
Subroutine set_ical: called CC=1 SCAR=0.0
12 107 my $self = shift;
13 # carp "set_ical $_[0] => @{$_[1]}" if @_;
14 107 $self->{as_ical} = [ @_ ];
15 107 $self;
16 }
17  
18 59 ▶sub get_ical {
Subroutine get_ical: called CC=2 SCAR=6.9
19 59 my $self = shift;
20 59 ▶ return unless $self->{as_ical};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"as_ical"} 21 38 59
21 38 return @{ $self->{as_ical} };
22 }
23  
24 31 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
25 31 my $self = shift;
26 31 my $new = $self->SUPER::clone( @_ );
27 31 $new->set_ical( $self->get_ical );
28 31 $new;
29 }
30  
31 14 ▶sub union {
Subroutine union: called CC=7 SCAR=20.4
32 14 my $self = shift;
33 14 my $new = $self->SUPER::union( @_ );
34  
35 # RFC2445 - op1, op2 must have no 'exclude'
36 14 my (%op1, %op2);
37 14 ▶ %op1 = ( $self->get_ical ) if ( UNIVERSAL::can( $self, 'get_ical' ) );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($self, "get_ical") 14 0 14
38 14 ▶ %op2 = ( $_[0]->get_ical ) if ( UNIVERSAL::can( $_[0], 'get_ical' ) );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_[0], "get_ical") 13 1 14
39 return $new if ( ( exists $op1{exclude} ) ||
40 14 ▶ ( exists $op2{exclude} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $op1{"exclude"} or exists $op2{"exclude"} 0 14 14
Condition33%1/3
exists $op1{"exclude"} or exists $op2{"exclude"}
l!l&&r!l&&!r
0014
MC/DC0%0/2
exists $op1{"exclude"} or exists $op2{"exclude"}
exists $op1{"exclude"} exists $op2{"exclude"}
Truth table33%1/3
A or B
A= exists $op1{"exclude"}B= exists $op2{"exclude"}
ABresult
1X1
011
000
41  
42 14 bless $new, 'DateTime::Set::ICal';
43 # warn " -- 1 isa @{[%op1]} -- 2 isa @{[%op2]} -- ";
44 14 my @ical;
45 @ical = exists $op1{include} ?
46 14 ▶ @{$op1{include}} :
Branch: 1 branch
BranchTrueFalseTotal
exists $op1{'include'} ? : 7 7 14
47 $self;
48  
49 # push @ical, @{$op2{include}}, @_;
50 14 ▶ if ( exists $op2{include} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op2{'include'}) { } 0 14 14
51 {
52 0 push @ical, @{$op2{include}};
53 }
54 else
55 {
56 14 push @ical, @_; # whatever...
57 }
58 # warn "union: @ical";
59 14 $new->set_ical( include => [ @ical ] );
60 14 $new;
61 }
62  
63 1 ▶sub complement {
Subroutine complement: called CC=8 SCAR=22.8
64 1 my $self = shift;
65 1 my $new = $self->SUPER::complement( @_ );
66 1 ▶ return $new unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
67  
68 # RFC2445 - op2 must have no 'exclude'
69 1 my (%op1, %op2);
70 1 ▶ %op1 = ( $self->get_ical ) if ( UNIVERSAL::can( $self, 'get_ical' ) );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($self, "get_ical") 1 0 1
71 1 ▶ %op2 = ( $_[0]->get_ical ) if ( UNIVERSAL::can( $_[0], 'get_ical' ) );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_[0], "get_ical") 0 1 1
72 1 ▶ return $new if ( exists $op2{exclude} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $op2{"exclude"} 0 1 1
73  
74 1 bless $new, 'DateTime::Set::ICal';
75 # warn " -- 1 isa @{[%op1]} -- 2 isa @{[%op2]} -- ";
76 1 my ( @include, @exclude );
77 @include = exists $op1{include} ?
78 1 ▶ @{$op1{include}} :
Branch: 1 branch
BranchTrueFalseTotal
exists $op1{'include'} ? : 1 0 1
79 $self;
80  
81 @exclude = exists $op1{exclude} ?
82 0 ▶ @{$op1{exclude}} :
Branch: 1 branch
BranchTrueFalseTotal
exists $op1{'exclude'} ? : 0 1 1
83 ();
84  
85 1 ▶ if ( exists $op2{include} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $op2{'include'}) { } 0 1 1
86 {
87 0 push @exclude, @{$op2{include}};
88 }
89 else
90 {
91 1 push @exclude, @_; # whatever...
92 }
93  
94 # warn "complement: include @include exclude @exclude";
95 1 $new->set_ical( include => [ @include ], exclude => [ @exclude ] );
96 1 $new;
97 }
98  
99 package DateTime::Event::Recurrence;
100  
101 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
102 15 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
103 15 ▶use DateTime::Set;
Subroutine BEGIN: called CC=1 SCAR=0.0
104 15 ▶use DateTime::Span;
Subroutine BEGIN: called CC=1 SCAR=0.0
105 15 ▶use Params::Validate qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
106 15 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
107 15 $VERSION = '0.19';
108  
109 15 ▶use constant INFINITY => 100 ** 100 ** 100 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
110 15 ▶use constant NEG_INFINITY => -1 * (100 ** 100 ** 100);
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 # -------- BASE OPERATIONS
113  
114 15 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
115 %as_number
116  
117 %truncate
118 %next_unit
119 %previous_unit
120
121 %truncate_interval
122 %next_unit_interval
123 %previous_unit_interval
124  
125 %weekdays
126 %weekdays_1
127 %weekdays_any
128
129 %memoized_duration
130
131 %ical_name
132 %ical_days
133 %limits
134 @units
135 15 );
136  
137 15 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
138 15 %weekdays = qw( mo 1 tu 2 we 3 th 4 fr 5 sa 6 su 7 );
139 15 %weekdays_1 = qw( 1mo 1 1tu 2 1we 3 1th 4 1fr 5 1sa 6 1su 7 );
140 15 %weekdays_any = ( %weekdays, %weekdays_1 );
141
142 15 %ical_name = qw(
143 months BYMONTH
144 weeks BYWEEKNO
145 days BYMONTHDAY
146 hours BYHOUR
147 minutes BYMINUTE
148 seconds BYSECOND
149 );
150
151 15 %ical_days = qw(
152 1 MO 2 TU 3 WE 4 TH 5 FR 6 SA 7 SU
153 -7 MO -6 TU -5 WE -4 TH -3 FR -2 SA -1 SU
154 );
155
156 15 @units = qw( years months weeks days hours minutes seconds nanoseconds );
157
158 15 %limits = qw(
159 nanoseconds 1000000000
160 seconds 61
161 minutes 60
162 hours 24
163 months 12
164 weeks 53
165 days 366
166 );
167  
168 } # BEGIN
169  
170  
171 # memoization reduces 'duration' creation from >10000 to about 30 per run,
172 # in DT::E::ICal
173  
174 17779 ▶sub _add {
Subroutine _add: called CC=2 SCAR=6.9
175 # datetime, unit, value
176 17779 my $dur = \$memoized_duration{$_[1]}{$_[2]};
177 17779 ▶ $$dur = new DateTime::Duration( $_[1] => $_[2] )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$dur 301 17478 17779
178 unless defined $$dur;
179 17779 $_[0]->add_duration( $$dur );
180 }
181  
182 # TODO: %as_number should use the "subtract" routines from DateTime
183  
184 %as_number = (
185 3983 ▶ years => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
186 3983 $_[0]->year
187 },
188 3413 ▶ months => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
189 3413 12 * $_[0]->year + $_[0]->month - 1
190 },
191 8898 ▶ days => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
192 8898 ( $_[0]->local_rd_values() )[0]
193 },
194 712 ▶ weeks => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
195 # $_[1] is the "week start day", such as "1mo"
196 15 ▶ use integer;
Subroutine BEGIN: called CC=1 SCAR=0.0
197 712 return ( $as_number{days}->( $_[0] ) - $weekdays_any{ $_[1] } ) / 7;
198 },
199 3755 ▶ hours => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
200 3755 $as_number{days}->($_[0]) * 24 + $_[0]->hour
201 },
202 768 ▶ minutes => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
203 768 $as_number{hours}->($_[0]) * 60 + $_[0]->minute
204 },
205 0 ▶ seconds => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
206 0 $_[0]->local_rd_as_seconds
207 },
208 1058 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
209 # get the internal year number, in 'week' mode
210 # $_[1] is the "week start day", such as "1mo"
211 1058 my $base = $_[0]->clone;
212 1058 ▶ $base = $truncate{years_weekly}->( $base, $_[1] )
Branch: 1 branch
BranchTrueFalseTotal
if $base->month > 11 or $base->month < 2 1058 0 1058
Condition66%2/3
$base->month > 11 or $base->month < 2
l!l&&r!l&&!r
4336250
MC/DC0%0/2
$base->month > 11 or $base->month < 2
$base->month > 11 $base->month < 2
Truth table66%2/3
A or B
A= $base->month > 11B= $base->month < 2
ABresult
1X1
011
000
213 if $base->month > 11 || $base->month < 2;
214 1058 _add( $base, weeks => 1 );
215 1058 return $as_number{years}->( $base );
216 },
217 585 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
218 # get the internal month number, in 'week' mode
219 # $_[1] is the "week start day", such as "1mo"
220 585 my $base = $_[0]->clone;
221 585 ▶ $base = $truncate{months_weekly}->( $base, $_[1] )
Branch: 1 branch
BranchTrueFalseTotal
if $base->day > 20 or $base->day < 7 518 67 585
Condition100%3/3
$base->day > 20 or $base->day < 7
l!l&&r!l&&!r
6345567
MC/DC100%2/2
$base->day > 20 or $base->day < 7
$base->day > 20 $base->day < 7
Truth table100%3/3
A or B
A= $base->day > 20B= $base->day < 7
ABresult
1X1
011
000
222 if $base->day > 20 || $base->day < 7;
223 585 _add( $base, weeks => 1 );
224 585 return $as_number{months}->( $base );
225 },
226 15 );
227  
228  
229 %truncate = (
230 # @_ = ( $datetime, $week_start_day )
231  
232 (
233 map {
234 90 my $name = $_;
235 90 $name =~ s/s$//;
236 0 ▶ $_ => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
237 0 my $tmp = $_[0]->clone;
238 0 $tmp->truncate( to => $name )
239 }
240 90 } qw( years months days hours minutes seconds )
241 ),
242  
243 104 ▶ weeks => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
244 104 my $base = $_[0]->clone->truncate( to => 'day' );
245 _add( $base, days => - $_[0]->day_of_week
246 104 + $weekdays_any{ $_[1] } );
247 104 while(1) {
248 110 ▶ return $base if $base <= $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $base <= $_[0] 104 6 110
249 6 _add( $base, weeks => -1 );
250 }
251 },
252  
253 869 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
254 869 my $tmp;
255 869 my $base = $_[0]->clone;
256 869 _add( $base, days => 7 );
257 869 $base->truncate( to => 'month' );
258 869 my $val;
259 my $diff;
260 869 while(1) {
261 933 $tmp = $base->clone;
262 933 $val = $weekdays_1{ $_[1] };
263 933 ▶ if ( $val )
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 747 186 933
264 {
265 747 $diff = $val - $base->day_of_week;
266 747 ▶ $diff += 7 if $diff < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $diff < 0 295 452 747
267 }
268 else
269 {
270 186 $diff = ( $weekdays{ $_[1] } -
271 $base->day_of_week ) % 7;
272 186 ▶ $diff -= 7 if $diff > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $diff > 3 101 85 186
273 }
274 933 _add( $tmp, days => $diff );
275 933 ▶ return $tmp if $tmp <= $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $tmp <= $_[0] 869 64 933
276 64 _add( $base, months => -1 );
277 }
278 },
279  
280 1852 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
281 1852 my $tmp;
282 1852 my $base = $_[0]->clone;
283 1852 _add( $base, months => 1 );
284 1852 $base->truncate( to => 'year' );
285 1852 my $val;
286 my $diff;
287 # warn "wsd $_[1]\n";
288 1852 while(1) {
289 2140 $tmp = $base->clone;
290 2140 $val = $weekdays_1{ $_[1] };
291 2140 ▶ if ( $val )
Branch: 1 branch
BranchTrueFalseTotal
if ($val) { } 485 1655 2140
292 {
293 485 $diff = $val - $base->day_of_week;
294 485 ▶ $diff += 7 if $diff < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $diff < 0 356 129 485
295 }
296 else
297 {
298 1655 $diff = ( $weekdays{ $_[1] } -
299 $base->day_of_week ) % 7;
300 1655 ▶ $diff -= 7 if $diff > 3;
Branch: 1 branch
BranchTrueFalseTotal
if $diff > 3 886 769 1655
301 }
302 2140 _add( $tmp, days => $diff );
303 2140 ▶ return $tmp if $tmp <= $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $tmp <= $_[0] 1852 288 2140
304 288 _add( $base, years => -1 );
305 }
306 },
307 15 );
308  
309 %next_unit = (
310 # @_ = ( $datetime, $week_start_day )
311  
312 (
313 map {
314 105 my $names = $_;
315 347 ▶ $_ => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
316 347 _add( $_[0], $names => 1 )
317 }
318 105 } qw( years months weeks days hours minutes seconds )
319 ),
320  
321 107 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
322 107 my $base = $_[0]->clone;
323 107 my $return;
324 107 while(1) {
325 214 _add( $base, days => 21 );
326 214 $return = $truncate{months_weekly}->( $base, $_[1] );
327 214 ▶ return $_[0] = $return if $return > $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $return > $_[0] 107 107 214
328 }
329 },
330  
331 254 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
332 254 my $base = $_[0]->clone;
333 254 my $return;
334 254 while(1) {
335 508 _add( $base, months => 11 );
336 508 $return = $truncate{years_weekly}->( $base, $_[1] );
337 508 ▶ return $_[0] = $return if $return > $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $return > $_[0] 254 254 508
338 }
339 },
340 15 );
341  
342 %previous_unit = (
343 # @_ = ( $datetime, $week_start_day )
344  
345 10 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
346 10 my $base = $_[0]->clone;
347 10 my $return;
348 10 while(1) {
349 20 $return = $truncate{months_weekly}->( $base, $_[1] );
350 20 ▶ return $_[0] = $return if $return < $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $return < $_[0] 10 10 20
351 10 _add( $base, days => -21 );
352 }
353 },
354  
355 32 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
356 32 my $base = $_[0]->clone;
357 32 my $return;
358 32 while(1) {
359 64 $return = $truncate{years_weekly}->( $base, $_[1] );
360 64 ▶ return $_[0] = $return if $return < $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $return < $_[0] 32 32 64
361 32 _add( $base, months => -11 );
362 }
363 },
364 15 );
365  
366 # -------- "INTERVAL" OPERATIONS
367  
368 %truncate_interval = (
369 # @_ = ( $datetime, $args )
370  
371 (
372 map {
373 90 my $names = $_;
374 90 my $name = $_;
375 90 $name =~ s/s$//;
376 733 ▶ $_ => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
377 733 my $tmp = $_[0]->clone;
378 733 $tmp->truncate( to => $name );
379 _add( $tmp, $names =>
380 $_[1]{offset} -
381 ( $as_number{$names}->($_[0]) %
382 $_[1]{interval}
383 )
384 733 );
385 }
386 90 } qw( years months days hours minutes seconds )
387 ),
388  
389 104 ▶ weeks => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
390 104 my $tmp = $truncate{weeks}->( $_[0], $_[1]{week_start_day} );
391 104 ▶ while ( $_[1]{offset} !=
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{"offset"} != $DateTime::Event::Recurrence::as_number{"weeks"}->($tmp, $_[1]{"week_start_day"}) % $_[1]{"interval"}) 0 104 104
392 ( $as_number{weeks}->(
393 $tmp, $_[1]{week_start_day} ) %
394 $_[1]{interval}
395 )
396 )
397 {
398 0 _add( $tmp, weeks => -1 );
399 }
400 104 return $tmp;
401 },
402  
403 117 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
404 117 my $tmp = $truncate{months_weekly}->( $_[0], $_[1]{week_start_day} );
405 117 ▶ while ( $_[1]{offset} !=
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{"offset"} != $DateTime::Event::Recurrence::as_number{"months_weekly"}->($tmp, $_[1]{"week_start_day"}) % $_[1]{"interval"}) 0 117 117
406 ( $as_number{months_weekly}->(
407 $tmp, $_[1]{week_start_day} ) %
408 $_[1]{interval}
409 )
410 )
411 {
412 0 $previous_unit{months_weekly}->( $tmp, $_[1]{week_start_day} );
413 }
414 117 return $tmp;
415 },
416  
417 222 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
418 222 my $tmp = $truncate{years_weekly}->( $_[0], $_[1]{week_start_day} );
419 222 ▶ while ( $_[1]{offset} !=
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{"offset"} != $DateTime::Event::Recurrence::as_number{"years_weekly"}->($tmp, $_[1]{"week_start_day"}) % $_[1]{"interval"}) 0 222 222
420 ( $as_number{years_weekly}->( $tmp, $_[1]{week_start_day} ) %
421 $_[1]{interval}
422 )
423 )
424 {
425 0 $previous_unit{years_weekly}->( $tmp, $_[1]{week_start_day} );
426 }
427 222 return $tmp;
428 },
429 15 );
430  
431 %next_unit_interval = (
432 (
433 map {
434 105 my $names = $_;
435 339 ▶ $_ => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
436 _add( $_[0], $names => $_[1]{interval} )
437 339 }
438 105 } qw( years months weeks days hours minutes seconds )
439 ),
440  
441 107 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
442 107 for ( 1 .. $_[1]{interval} )
443 {
444 107 $next_unit{months_weekly}->( $_[0], $_[1]{week_start_day} );
445 }
446 },
447  
448 164 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
449 164 for ( 1 .. $_[1]{interval} )
450 {
451 164 $next_unit{years_weekly}->( $_[0], $_[1]{week_start_day} );
452 }
453 },
454 15 );
455  
456 %previous_unit_interval = (
457 (
458 map {
459 105 my $names = $_;
460 138 ▶ $_ => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
461 _add( $_[0], $names => - $_[1]{interval} )
462 138 }
463 105 } qw( years months weeks days hours minutes seconds )
464 ),
465  
466 10 ▶ months_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
467 10 for ( 1 .. $_[1]{interval} )
468 {
469 10 $previous_unit{months_weekly}->( $_[0], $_[1]{week_start_day} );
470 }
471 },
472  
473 32 ▶ years_weekly => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
474 32 for ( 1 .. $_[1]{interval} )
475 {
476 32 $previous_unit{years_weekly}->( $_[0], $_[1]{week_start_day} );
477 }
478 },
479 15 );
480  
481 # -------- CONSTRUCTORS
482  
483 15 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
484 # setup all constructors: daily, ...
485  
486 15 for ( @units[ 0 .. $#units-1 ] )
487 {
488 105 my $name = $_;
489 105 my $namely = $_;
490 105 $namely =~ s/ys$/ily/;
491 105 $namely =~ s/s$/ly/;
492
493 15 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
494 105 *{__PACKAGE__ . "::$namely"} =
495 63 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
496 15 ▶ use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
497 63 my $class = shift;
498 63 return _create_recurrence( base => $name, @_ );
499 105 };
500 }
501 } # BEGIN
502  
503  
504 63 ▶sub _create_recurrence {
Subroutine _create_recurrence: called CC=57 SCAR=40.7
505 63 my %args = @_;
506  
507 # print "ARGS: ";
508 # for(@_){ print (( ref($_) eq "ARRAY" ) ? "[ @$_ ] " : "$_ ") }
509 # print " \n";
510
511 # --- FREQUENCY
512
513 63 my $base = delete $args{base};
514 63 my $namely = $base;
515 63 $namely =~ s/ys$/ily/;
516 63 $namely =~ s/s$/ly/;
517 63 my $ical_string = uc( "RRULE:FREQ=$namely" );
518 63 my $base_unit = $base;
519 $base_unit = 'years_weekly'
520 if $base_unit eq 'years' &&
521 63 ▶ exists $args{weeks} ;
Branch: 1 branch
BranchTrueFalseTotal
if $base_unit eq "years" and exists $args{"weeks"} 16 47 63
Condition100%3/3
$base_unit eq "years" and exists $args{"weeks"}
!ll&&!rl&&r
351216
MC/DC100%2/2
$base_unit eq "years" and exists $args{"weeks"}
$base_unit eq "years" exists $args{"weeks"}
Truth table100%3/3
A and B
A= $base_unit eq "years"B= exists $args{"weeks"}
ABresult
0X0
100
111
522 $base_unit = 'months_weekly'
523 if $base_unit eq 'months' &&
524 63 ▶ exists $args{weeks} ;
Branch: 1 branch
BranchTrueFalseTotal
if $base_unit eq "months" and exists $args{"weeks"} 5 58 63
Condition100%3/3
$base_unit eq "months" and exists $args{"weeks"}
!ll&&!rl&&r
5175
MC/DC100%2/2
$base_unit eq "months" and exists $args{"weeks"}
$base_unit eq "months" exists $args{"weeks"}
Truth table100%3/3
A and B
A= $base_unit eq "months"B= exists $args{"weeks"}
ABresult
0X0
100
111
525  
526 # --- WEEK-START-DAY
527
528 63 my $week_start_day = delete $args{week_start_day};
529 63 ▶ $ical_string .= ";WKST=". uc($week_start_day)
Branch: 1 branch
BranchTrueFalseTotal
if $week_start_day 18 45 63
530 if $week_start_day;
531 63 ▶ $week_start_day = ( $base eq 'years' ) ? 'mo' : '1mo'
Branch: 2 branches
BranchTrueFalseTotal
unless defined $week_start_day 45 18 63
$base eq 'years' ? : 18 27 45
532 unless defined $week_start_day;
533 die "$base: invalid week start day ($week_start_day)"
534 63 ▶ unless $weekdays_any{ $week_start_day };
Branch: 1 branch
BranchTrueFalseTotal
unless $DateTime::Event::Recurrence::weekdays_any{$week_start_day} 0 63 63
535
536 # --- INTERVAL, START, and OFFSET
537
538 63 ▶ my $interval = delete $args{interval} || 1;
Condition50%1/2
delete $args{'interval'} || 1
l!l
063
MC/DC0%0/1
delete $args{'interval'} || 1
delete $args{'interval'}
Truth table50%1/2
A
A= delete $args{'interval'}
Aresult
11
00
539 63 ▶ die "invalid 'interval' specification ($interval)"
Branch: 1 branch
BranchTrueFalseTotal
if $interval < 1 0 63 63
540 if $interval < 1;
541 63 ▶ $ical_string .= ";INTERVAL=$interval"
Branch: 1 branch
BranchTrueFalseTotal
if $interval > 1 0 63 63
542 if $interval > 1;
543  
544 63 my $start = delete $args{start};
545 63 ▶ undef $start
Branch: 1 branch
BranchTrueFalseTotal
if defined $start and $start->is_infinite 0 63 63
Condition33%1/3
defined $start and $start->is_infinite
!ll&&!rl&&r
6300
MC/DC0%0/2
defined $start and $start->is_infinite
defined $start $start->is_infinite
Truth table33%1/3
A and B
A= defined $startB= $start->is_infinite
ABresult
0X0
100
111
546 if defined $start && $start->is_infinite;
547
548 63 my $offset = 0;
549 63 ▶ $offset = $as_number{$base_unit}->( $start, $week_start_day ) % $interval
Branch: 1 branch
BranchTrueFalseTotal
if $start and $interval > 1 0 63 63
Condition33%1/3
$start and $interval > 1
!ll&&!rl&&r
6300
MC/DC0%0/2
$start and $interval > 1
$start $interval > 1
Truth table33%1/3
A and B
A= $startB= $interval > 1
ABresult
0X0
100
111
550 if $start && $interval > 1;
551  
552 # --- DURATION LIST
553
554 # check for invalid "units" arguments, such as "daily( years=> )"
555 63 my @valid_units;
556 63 for ( 0 .. $#units )
557 {
558 136 ▶ if ( $base eq $units[$_] )
Branch: 1 branch
BranchTrueFalseTotal
if ($base eq $DateTime::Event::Recurrence::units[$_]) 63 73 136
559 {
560 63 @valid_units = @units[ $_+1 .. $#units ];
561 63 last;
562 }
563 }
564 die "can't have both 'months' and 'weeks' arguments"
565 if exists $args{weeks} &&
566 63 ▶ exists $args{months};
Branch: 1 branch
BranchTrueFalseTotal
if exists $args{"weeks"} and exists $args{"months"} 0 63 63
Condition66%2/3
exists $args{"weeks"} and exists $args{"months"}
!ll&&!rl&&r
42210
MC/DC0%0/2
exists $args{"weeks"} and exists $args{"months"}
exists $args{"weeks"} exists $args{"months"}
Truth table66%2/3
A and B
A= exists $args{"weeks"}B= exists $args{"months"}
ABresult
0X0
100
111
567
568 63 my $level = 1;
569 63 my @duration = ( [] );
570 63 my @level_unit = ( $base_unit );
571 63 for my $unit ( @valid_units )
572 {
573 364 ▶ next unless exists $args{$unit};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{$unit} 264 100 364
574  
575 100 ▶ if ( ref( $args{$unit} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{$unit} eq 'ARRAY') { } 61 39 100
576 {
577 61 $args{$unit} = [ @{ $args{$unit} } ]
578 }
579 else
580 {
581 39 $args{$unit} = [ $args{$unit} ]
582 }
583
584 # TODO: sort _after_ normalization
585  
586 100 ▶ if ( $unit eq 'days' )
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "days") 27 73 100
587 {
588 # map rfc2445 weekdays to numbers
589 27 @{$args{$unit}} =
590 map {
591 149 ▶ $_ =~ /[a-z]/ ? $weekdays{$_} : $_
Branch: 1 branch
BranchTrueFalseTotal
$_ =~ /[a-z]/ ? : 3 146 149
592 27 } @{$args{$unit}};
593 }
594  
595 # sort positive values first
596 100 @{$args{$unit}} =
597 sort {
598 381 ▶ ( $a < 0 ) <=> ( $b < 0 ) || $a <=> $b
Condition100%3/3
$a < 0 <=> $b < 0 || $a <=> $b
l!l&&r!l&&!r
183612
MC/DC100%2/2
$a < 0 <=> $b < 0 || $a <=> $b
$a < 0 <=> $b < 0 $a <=> $b
Truth table100%3/3
A || B
A= $a < 0 <=> $b < 0B= $a <=> $b
ABresult
1X1
011
000
599 100 } @{$args{$unit}};
600  
601  
602 # make the "ical" string
603 100 ▶ if ( $unit eq 'nanoseconds' )
Branch: 2 branches
BranchTrueFalseTotal
if ($unit eq 'nanoseconds') { } 1 99 100
elsif ($base eq 'weeks' and $unit eq 'days') { } 6 93 99
604 {
605 # there are no nanoseconds in ICal
606 }
607 ▶ elsif ( $base eq 'weeks' &&
Condition66%2/3
$base eq "weeks" and $unit eq "days"
!ll&&!rl&&r
9306
MC/DC50%1/2
$base eq "weeks" and $unit eq "days"
$base eq "weeks" $unit eq "days"
Truth table66%2/3
A and B
A= $base eq "weeks"B= $unit eq "days"
ABresult
0X0
100
111
608 $unit eq 'days' )
609 {
610 # weekdays have names
611 $ical_string .= uc( ';' . 'BYDAY' . '=' .
612 join(",",
613 map {
614 6 ▶ exists( $ical_days{$_} ) ? $ical_days{$_} : $_
Branch: 1 branch
BranchTrueFalseTotal
exists $DateTime::Event::Recurrence::ical_days{$_} ? : 6 0 6
615 6 } @{$args{$unit}} )
616 )
617 }
618 else
619 {
620 $ical_string .= uc( ';' . $ical_name{$unit} . '=' .
621 93 join(",", @{$args{$unit}} ) )
622 }
623
624 100 ▶ if ( $unit eq 'months' ||
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "months" or $unit eq "weeks" or $unit eq "days") 58 42 100
Condition100%6/6
$unit eq "months" or $unit eq "weeks" or $unit eq "days"
l!l&&r!l&&!r
312742
$unit eq "months" or $unit eq "weeks"
l!l&&r!l&&!r
102169
MC/DC100%3/3
$unit eq "months" or $unit eq "weeks" or $unit eq "days"
$unit eq "months" $unit eq "weeks" $unit eq "days"
Truth table100%4/4
A or B or C
A= $unit eq "months"B= $unit eq "weeks"C= $unit eq "days"
ABCresult
1XX1
01X1
0011
0000
625 $unit eq 'weeks' ||
626 $unit eq 'days' )
627 {
628 # these units start in '1'
629 58 for ( @{$args{$unit}} )
630 {
631 211 ▶ die $unit . ' cannot be zero'
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 211 211
632 unless $_;
633 211 ▶ $_-- if $_ > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ > 0 174 37 211
634 }
635 }
636
637 100 @{$args{$unit}} =
638 grep {
639 $_ < $limits{ $unit } &&
640 431 ▶ $_ >= - $limits{ $unit }
Condition66%2/3
$_ < $DateTime::Event::Recurrence::limits{$unit} && $_ >= -$DateTime::Event::Recurrence::limits{$unit}
!ll&&!rl&&r
30428
MC/DC50%1/2
$_ < $DateTime::Event::Recurrence::limits{$unit} && $_ >= -$DateTime::Event::Recurrence::limits{$unit}
$_ < $DateTime::Event::Recurrence::limits{$unit} $_ >= -$DateTime::Event::Recurrence::limits{$unit}
Truth table66%2/3
A && B
A= $_ < $DateTime::Event::Recurrence::limits{$unit}B= $_ >= -$DateTime::Event::Recurrence::limits{$unit}
ABresult
0X0
100
111
641 100 } @{$args{$unit}};
642
643 100 ▶ if ( $unit eq 'days' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "days" and $base_unit eq "months" || $level_unit[-1] eq "months") 16 84 100
Condition100%6/6
$unit eq "days" and $base_unit eq "months" || $level_unit[-1] eq "months"
!ll&&!rl&&r
731116
$base_unit eq "months" or $level_unit[-1] eq "months"
l!l&&r!l&&!r
61011
MC/DC100%3/3
$unit eq "days" and $base_unit eq "months" || $level_unit[-1] eq "months"
$unit eq "days" $base_unit eq "months" $level_unit[-1] eq "months"
Truth table100%4/4
A and B or C
A= $unit eq "days"B= $base_unit eq "months"C= $level_unit[-1] eq "months"
ABCresult
0XX0
1000
11X1
1011
644 ( $base_unit eq 'months' ||
645 $level_unit[-1] eq 'months' ) )
646 { # month day
647 16 @{$args{$unit}} =
648 grep {
649 138 ▶ $_ < 31 && $_ >= -31
Condition66%2/3
$_ < 31 && $_ >= -31
!ll&&!rl&&r
10137
MC/DC50%1/2
$_ < 31 && $_ >= -31
$_ < 31 $_ >= -31
Truth table66%2/3
A && B
A= $_ < 31B= $_ >= -31
ABresult
0X0
100
111
650 16 } @{$args{$unit}};
651 }
652  
653 100 ▶ if ( $unit eq 'days' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($unit eq "days" and $base_unit eq "weeks" || $level_unit[-1] eq "weeks") 10 90 100
Condition100%6/6
$unit eq "days" and $base_unit eq "weeks" || $level_unit[-1] eq "weeks"
!ll&&!rl&&r
731710
$base_unit eq "weeks" or $level_unit[-1] eq "weeks"
l!l&&r!l&&!r
6417
MC/DC100%3/3
$unit eq "days" and $base_unit eq "weeks" || $level_unit[-1] eq "weeks"
$unit eq "days" $base_unit eq "weeks" $level_unit[-1] eq "weeks"
Truth table100%4/4
A and B or C
A= $unit eq "days"B= $base_unit eq "weeks"C= $level_unit[-1] eq "weeks"
ABCresult
0XX0
1000
11X1
1011
654 ( $base_unit eq 'weeks' ||
655 $level_unit[-1] eq 'weeks' ) )
656 { # week day
657
658 10 @{$args{$unit}} =
659 grep {
660 10 ▶ $_ < 7 && $_ >= -7
Condition33%1/3
$_ < 7 && $_ >= -7
!ll&&!rl&&r
0010
MC/DC0%0/2
$_ < 7 && $_ >= -7
$_ < 7 $_ >= -7
Truth table33%1/3
A && B
A= $_ < 7B= $_ >= -7
ABresult
0X0
100
111
661 10 } @{$args{$unit}};
662  
663 10 for ( @{$args{$unit}} )
664 {
665 10 $_ = $_ - $weekdays_any{ $week_start_day } + 1;
666 10 ▶ $_ += 7 while $_ < 0;
Branch: 1 branch
BranchTrueFalseTotal
$_ < 0 and do { $_ += 7 } 1 10 11
667 }
668  
669 10 @{$args{$unit}} = sort @{$args{$unit}};
670 }
671  
672 return DateTime::Set::ICal->empty_set
673 100 ▶ unless @{$args{$unit}}; # there are no args left
Branch: 1 branch
BranchTrueFalseTotal
unless @{$args{$unit};} 1 99 100
674  
675 99 push @duration, $args{$unit};
676 99 push @level_unit, $unit;
677  
678 99 delete $args{$unit};
679  
680 99 $level++;
681 }
682  
683 # TODO: use $span for selecting elements (using intersection)
684 # note - this may change the documented behaviour - check the pod first
685 # $span = delete $args{span};
686 # $span = DateTime::Span->new( %args ) if %args;
687  
688 62 ▶ die "invalid argument '@{[ keys %args ]}'"
Branch: 1 branch
BranchTrueFalseTotal
if keys %args 1 61 62
689 if keys %args;
690
691 # --- SPLIT NEGATIVE/POSITIVE DURATIONS
692  
693 61 my @args;
694 61 push @args, \@duration;
695
696 61 ▶ for ( my $i = 0; $i < @args; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @args) 74 61 135
697 {
698 74 my $dur1 = $args[$i];
699 74 for ( 1 .. $#{$dur1} )
700 {
701 121 my @negatives = grep { $_ < 0 } @{$dur1->[$_]};
702 121 my @positives = grep { $_ >= 0 } @{$dur1->[$_]};
703 121 ▶ if ( @positives && @negatives )
Branch: 1 branch
BranchTrueFalseTotal
if (@positives and @negatives) 13 108 121
Condition100%3/3
@positives and @negatives
!ll&&!rl&&r
208813
MC/DC100%2/2
@positives and @negatives
@positives @negatives
Truth table100%3/3
A and B
A= @positivesB= @negatives
ABresult
0X0
100
111
704 {
705 # split
706 # TODO: check if it really needs splitting
707 13 my $dur2 = [ @{$args[$i]} ];
708 13 $dur2->[$_] = \@negatives;
709 13 $dur1->[$_] = \@positives;
710 13 push @args, $dur2;
711 }
712 }
713 }
714  
715 # --- CREATE THE SET
716
717 61 my $set;
718 61 for ( @args )
719 {
720 74 my @duration = @$_;
721 74 my $total_durations = 1;
722 74 my @total_level;
723 74 ▶ for ( my $i = $#duration; $i > 0; $i-- )
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 121 74 195
724 {
725 121 ▶ if ( $i == $#duration )
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $#duration) { } 68 53 121
726 {
727 68 $total_level[$i] = 1;
728 }
729 else
730 {
731 $total_level[$i] = $total_level[$i + 1] *
732 53 ( 1 + $#{ $duration[$i + 1] } );
733 }
734 121 $total_durations *= 1 + $#{ $duration[$i] };
735 }
736  
737 my $args = {
738 truncate_interval => $truncate_interval{ $base_unit },
739 previous_unit_interval => $previous_unit_interval{ $base_unit },
740 74 next_unit_interval => $next_unit_interval{ $base_unit },
741
742 duration => \@duration,
743 total_durations => $total_durations,
744 level_unit => \@level_unit,
745 total_level => \@total_level,
746
747 interval => $interval,
748 offset => $offset,
749 week_start_day => $week_start_day,
750 };
751
752 my $tmp = DateTime::Set::ICal->from_recurrence(
753 1084 ▶ next => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
754 1084 _get_next( $_[0], $args );
755 },
756 525 ▶ previous => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
757 525 _get_previous( $_[0], $args );
758 },
759 74 );
760
761 74 ▶ $set = defined $set ? $set->union( $tmp ) : $tmp;
Branch: 1 branch
BranchTrueFalseTotal
defined $set ? : 13 61 74
762 }
763 61 $set->set_ical( include => [ $ical_string ] );
764 # warn "Creating set: ". $ical_string ." \n";
765
766 61 return $set;
767
768 } # _create_recurrence
769  
770  
771 3063 ▶sub _get_occurrence_by_index {
Subroutine _get_occurrence_by_index: called CC=7 SCAR=19.5
772 3063 my ( $base, $occurrence, $args ) = @_;
773 # TODO: memoize "occurrences" within an "INTERVAL" ???
774 3063 RETRY_OVERFLOW: for ( 0 .. 5 )
775 {
776 return undef
777 3171 ▶ if $occurrence < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $occurrence < 0 34 3137 3171
778 3137 my $next = $base->clone;
779 3137 my $previous = $base;
780 3137 my @values = ( -1 );
781 3137 for my $j ( 1 .. $#{$args->{duration}} )
782 {
783 # decode the occurrence-number into a parameter-index
784 7559 my $i = int( $occurrence / $args->{total_level}[$j] );
785 7559 $occurrence -= $i * $args->{total_level}[$j];
786 7559 push @values, $i;
787
788 7559 ▶ if ( $args->{duration}[$j][$i] < 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"duration"}[$j][$i] < 0) 437 7122 7559
789 {
790 # warn "negative unit\n";
791 $next_unit{ $args->{level_unit}[$j - 1] }->(
792 437 $next, $args->{week_start_day} );
793 }
794 7559 _add( $next, $args->{level_unit}[$j], $args->{duration}[$j][$i] );
795
796 # overflow check
797 7559 ▶ if ( $as_number{ $args->{level_unit}[$j - 1] }->(
Branch: 1 branch
BranchTrueFalseTotal
if ($DateTime::Event::Recurrence::as_number{$args->{"level_unit"}[$j - 1]}($next, $args->{"week_start_day"}) != $DateTime::Event::Recurrence::as_number{$args->{"level_unit"}[$j - 1]}($previous, $args->{"week_start_day"})) 108 7451 7559
798 $next, $args->{week_start_day} ) !=
799 $as_number{ $args->{level_unit}[$j - 1] }->(
800 $previous, $args->{week_start_day} )
801 )
802 {
803 # calculate the "previous" occurrence-number
804 108 $occurrence = -1;
805 108 for ( 1 .. $j )
806 {
807 203 $occurrence += $values[$_] * $args->{total_level}[$_];
808 }
809 108 next RETRY_OVERFLOW;
810 }
811 7451 $previous = $next->clone;
812 }
813 3029 return $next;
814 }
815 0 return undef;
816 }
817  
818  
819 525 ▶sub _get_previous {
Subroutine _get_previous: called CC=10 SCAR=23.1
820 525 my ( $self, $args ) = @_;
821  
822 525 ▶ return $self if $self->is_infinite;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_infinite 207 318 525
823 318 $self->set_time_zone( 'floating' );
824  
825 318 my $base = $args->{truncate_interval}->( $self, $args );
826 318 my ( $next, $i, $start, $end );
827 318 my $init = 0;
828 318 my $retry = 30;
829  
830 318 INTERVAL: while(1) {
831 498 ▶ $args->{previous_unit_interval}->( $base, $args ) if $init;
Branch: 1 branch
BranchTrueFalseTotal
if $init 180 318 498
832 498 $init = 1;
833  
834 # binary search
835 498 $start = 0;
836 498 $end = $args->{total_durations} - 1;
837 498 ▶ while ( $retry-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retry--) 844 0 844
838 844 ▶ if ( $end - $start < 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $start < 3) 498 346 844
839 {
840 498 ▶ for ( $i = $end; $i >= $start; $i-- )
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $start) 635 180 815
841 {
842 635 $next = _get_occurrence_by_index ( $base, $i, $args );
843 635 ▶ next INTERVAL unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 635 635
844 635 ▶ return $next if $next < $self;
Branch: 1 branch
BranchTrueFalseTotal
if $next < $self 318 317 635
845 }
846 180 next INTERVAL;
847 }
848  
849 346 $i = int( $start + ( $end - $start ) / 2 );
850 346 $next = _get_occurrence_by_index ( $base, $i, $args );
851 346 ▶ next INTERVAL unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 346 346
852  
853 346 ▶ if ( $next < $self )
Branch: 1 branch
BranchTrueFalseTotal
if ($next < $self) { } 189 157 346
854 {
855 189 $start = $i;
856 }
857 else
858 {
859 157 $end = $i - 1;
860 }
861 }
862 0 return undef;
863 }
864 }
865  
866  
867 1084 ▶sub _get_next {
Subroutine _get_next: called CC=10 SCAR=23.0
868 1084 my ( $self, $args ) = @_;
869  
870 1084 ▶ return $self if $self->is_infinite;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_infinite 226 858 1084
871 858 $self->set_time_zone( 'floating' );
872  
873 858 my $base = $args->{truncate_interval}->( $self, $args );
874 858 my ( $next, $i, $start, $end );
875 858 my $init = 0;
876 858 my $retry = 30;
877
878 858 INTERVAL: while(1) {
879 1468 ▶ $args->{next_unit_interval}->( $base, $args ) if $init;
Branch: 1 branch
BranchTrueFalseTotal
if $init 610 858 1468
880 1468 $init = 1;
881  
882 # binary search
883 1468 $start = 0;
884 1468 $end = $args->{total_durations} - 1;
885 1468 ▶ while ( $retry-- ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retry--) 1893 1 1894
886 1893 ▶ if ( $end - $start < 3 )
Branch: 1 branch
BranchTrueFalseTotal
if ($end - $start < 3) 1467 426 1893
887 {
888 1467 for $i ( $start .. $end )
889 {
890 1656 $next = _get_occurrence_by_index ( $base, $i, $args );
891 1656 ▶ next INTERVAL unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 34 1622 1656
892 1622 ▶ return $next if $next > $self;
Branch: 1 branch
BranchTrueFalseTotal
if $next > $self 857 765 1622
893 }
894 576 next INTERVAL;
895 }
896  
897 426 $i = int( $start + ( $end - $start ) / 2 );
898 426 $next = _get_occurrence_by_index ( $base, $i, $args );
899 426 ▶ next INTERVAL unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 426 426
900  
901 426 ▶ if ( $next > $self )
Branch: 1 branch
BranchTrueFalseTotal
if ($next > $self) { } 212 214 426
902 {
903 212 $end = $i;
904 }
905 else
906 {
907 214 $start = $i + 1;
908 }
909 }
910 1 return undef;
911 }
912 }
913  
914 15 1;
915  
916 __END__
↑ Summary