DateTime/SpanSet.pm

filter: Statementstmt 79.0% 227 / 287 Branchbran 55.6% 89 / 160 Conditioncond 42.4% 14 / 33 MC/DCmcdc 9.0% 2 / 22 Subroutinesub 75.6% 31 / 41 Podpod 100% 28 / 28 totaltotal 68.4% 391 / 571 CC 96 SCAR 21.3
CC
96
Cov
69%
complement
30.0
intersects
20.5
contains
13.4
CRAP 8.4
« Set/Infinite/_recurrence.pm ↑ Summary DateTime/Span.pm »
1 # Copyright (c) 2003 Flavio Soibelmann Glock. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
4  
5 package DateTime::SpanSet;
6  
7 23 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 23 ▶use DateTime::Set;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 23 ▶use DateTime::Infinite;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 23 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 23 ▶use Params::Validate qw( validate SCALAR BOOLEAN OBJECT CODEREF ARRAYREF );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 23 ▶use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 23 ▶use constant INFINITY => 100 ** 100 ** 100 ;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 23 ▶use constant NEG_INFINITY => -1 * (100 ** 100 ** 100);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 23 $VERSION = $DateTime::Set::VERSION;
19  
20 0 ▶sub iterate {
Subroutine iterate: not called CC=1 SCAR=6.9
Pod documented
21 0 my ( $self, $callback ) = @_;
22 0 my $class = ref( $self );
23 0 my $return = $class->empty_set;
24 $return->{set} = $self->{set}->iterate(
25 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
26 0 my $span = bless { set => $_[0] }, 'DateTime::Span';
27 0 $callback->( $span->clone );
28 $span = $span->{set}
29 0 ▶ if UNIVERSAL::can( $span, 'union' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($span, "union") 0 0 0
30 0 return $span;
31 }
32 0 );
33 0 $return;
34 }
35  
36 1 ▶sub map {
Subroutine map: called CC=2 SCAR=6.9
Pod documented
37 1 my ( $self, $callback ) = @_;
38 1 my $class = ref( $self );
39 1 ▶ die "The callback parameter to map() must be a subroutine reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 1 1
40 unless ref( $callback ) eq 'CODE';
41 1 my $return = $class->empty_set;
42 $return->{set} = $self->{set}->iterate(
43 2 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
44 2 local $_ = bless { set => $_[0]->clone }, 'DateTime::Span';
45 2 my @list = $callback->();
46 2 my $set = $class->empty_set;
47 2 $set = $set->union( $_ ) for @list;
48 2 return $set->{set};
49 }
50 1 );
51 1 $return;
52 }
53  
54 0 ▶sub grep {
Subroutine grep: not called CC=2 SCAR=17.9
Pod documented
55 0 my ( $self, $callback ) = @_;
56 0 my $class = ref( $self );
57 0 ▶ die "The callback parameter to grep() must be a subroutine reference"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $callback eq "CODE" 0 0 0
58 unless ref( $callback ) eq 'CODE';
59 0 my $return = $class->empty_set;
60 $return->{set} = $self->{set}->iterate(
61 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
62 0 local $_ = bless { set => $_[0]->clone }, 'DateTime::Span';
63 0 my $result = $callback->();
64 0 ▶ return $_->{set} if $result && $_;
Branch: 1 branch
BranchTrueFalseTotal
if $result and $_ 0 0 0
Condition0%0/3
$result and $_
!ll&&!rl&&r
000
MC/DC0%0/2
$result and $_
$result $_
Truth table0%0/3
A and B
A= $resultB= $_
ABresult
0X0
100
111
65 0 return;
66 }
67 0 );
68 0 $return;
69 }
70  
71 0 ▶sub set_time_zone {
Subroutine set_time_zone: not called CC=1 SCAR=6.9
Pod documented
72 0 my ( $self, $tz ) = @_;
73  
74 # TODO - use iterate() instead
75  
76 my $result = $self->{set}->iterate(
77 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
78 0 my %tmp = %{ $_[0]->{list}[0] };
79 0 ▶ $tmp{a} = $tmp{a}->clone->set_time_zone( $tz ) if ref $tmp{a};
Branch: 1 branch
BranchTrueFalseTotal
if ref $tmp{"a"} 0 0 0
80 0 ▶ $tmp{b} = $tmp{b}->clone->set_time_zone( $tz ) if ref $tmp{b};
Branch: 1 branch
BranchTrueFalseTotal
if ref $tmp{"b"} 0 0 0
81 0 \%tmp;
82 },
83 0 ▶ backtrack_callback => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
84 0 my ( $min, $max ) = ( $_[0]->min, $_[0]->max );
85 0 ▶ if ( ref($min) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $min) 0 0 0
86 {
87 0 $min = $min->clone;
88 0 $min->set_time_zone( 'floating' );
89 }
90 0 ▶ if ( ref($max) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $max) 0 0 0
91 {
92 0 $max = $max->clone;
93 0 $max->set_time_zone( 'floating' );
94 }
95 0 return Set::Infinite::_recurrence->new( $min, $max );
96 },
97 0 );
98  
99 ### this code enables 'subroutine method' behaviour
100 0 $self->{set} = $result;
101 0 return $self;
102 }
103  
104 5 ▶sub from_spans {
Subroutine from_spans: called CC=2 SCAR=6.9
Pod documented
105 5 my $class = shift;
106 5 my %args = validate( @_,
107 { spans =>
108 { type => ARRAYREF,
109 optional => 1,
110 },
111 }
112 );
113 5 my $self = {};
114 5 my $set = Set::Infinite::_recurrence->new();
115 5 $set = $set->union( $_->{set} ) for @{ $args{spans} };
116 5 $self->{set} = $set;
117 5 bless $self, $class;
118 5 return $self;
119 }
120  
121 3 ▶sub from_set_and_duration {
Subroutine from_set_and_duration: called CC=5 SCAR=17.6
Pod documented
122 # set => $dt_set, days => 1
123 3 my $class = shift;
124 3 my %args = @_;
125 my $set = delete $args{set} ||
126 3 ▶ carp "from_set_and_duration needs a 'set' parameter";
Condition33%1/3
delete $args{'set'} || carp(q[from_set_and_duration needs a 'set' parameter])
l!l&&r!l&&!r
300
MC/DC0%0/2
delete $args{'set'} || carp(q[from_set_and_duration needs a 'set' parameter])
delete $args{'set'} carp(q[from_set_and_duration needs a 'set' parameter])
Truth table33%1/3
A || B
A= delete $args{'set'}B= carp(q[from_set_and_duration needs a 'set' parameter])
ABresult
1X1
011
000
127  
128 3 ▶ $set = $set->as_set
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($set, "as_set") 0 3 3
129 if UNIVERSAL::can( $set, 'as_set' );
130 3 ▶ unless ( UNIVERSAL::can( $set, 'union' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($set, "union")) 0 3 3
131 0 carp "'set' must be a set" };
132  
133 my $duration = delete $args{duration} ||
134 3 ▶ new DateTime::Duration( %args );
Condition66%2/3
delete $args{'duration'} || 'DateTime::Duration'->new(%args)
l!l&&r!l&&!r
120
MC/DC0%0/2
delete $args{'duration'} || 'DateTime::Duration'->new(%args)
delete $args{'duration'} 'DateTime::Duration'->new(%args)
Truth table66%2/3
A || B
A= delete $args{'duration'}B= 'DateTime::Duration'->new(%args)
ABresult
1X1
011
000
135 3 my $end_set = $set->clone->add_duration( $duration );
136 3 return $class->from_sets( start_set => $set,
137 end_set => $end_set );
138 }
139  
140 13 ▶sub from_sets {
Subroutine from_sets: called CC=5 SCAR=17.1
Pod documented
141 13 my $class = shift;
142 13 my %args = validate( @_,
143 { start_set =>
144 { # can => 'union',
145 optional => 0,
146 },
147 end_set =>
148 { # can => 'union',
149 optional => 0,
150 },
151 }
152 );
153 13 my $start_set = delete $args{start_set};
154 13 my $end_set = delete $args{end_set};
155  
156 13 ▶ $start_set = $start_set->as_set
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($start_set, "as_set") 0 13 13
157 if UNIVERSAL::can( $start_set, 'as_set' );
158 13 ▶ $end_set = $end_set->as_set
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($end_set, "as_set") 0 13 13
159 if UNIVERSAL::can( $end_set, 'as_set' );
160  
161 13 ▶ unless ( UNIVERSAL::can( $start_set, 'union' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($start_set, "union")) 0 13 13
162 0 carp "'start_set' must be a set" };
163 13 ▶ unless ( UNIVERSAL::can( $end_set, 'union' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (UNIVERSAL::can($end_set, "union")) 0 13 13
164 0 carp "'end_set' must be a set" };
165  
166 13 my $self;
167 $self->{set} = $start_set->{set}->until(
168 13 $end_set->{set} );
169 13 bless $self, $class;
170 13 return $self;
171 }
172  
173 8 ▶sub start_set {
Subroutine start_set: called CC=3 SCAR=11.0
Pod documented
174 8 ▶ if ( exists $_[0]->{set}{method} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until") 5 3 8
Condition66%2/3
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
!ll&&!rl&&r
305
MC/DC50%1/2
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
exists $_[0]{"set"}{"method"} $_[0]{"set"}{"method"} eq "until"
Truth table66%2/3
A and B
A= exists $_[0]{"set"}{"method"}B= $_[0]{"set"}{"method"} eq "until"
ABresult
0X0
100
111
175 $_[0]->{set}{method} eq 'until' )
176 {
177 5 return bless { set => $_[0]->{set}{parent}[0] }, 'DateTime::Set';
178 }
179 3 my $return = DateTime::Set->empty_set;
180 3 $return->{set} = $_[0]->{set}->start_set;
181 3 $return;
182 }
183  
184 7 ▶sub end_set {
Subroutine end_set: called CC=3 SCAR=11.0
Pod documented
185 7 ▶ if ( exists $_[0]->{set}{method} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until") 5 2 7
Condition66%2/3
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
!ll&&!rl&&r
205
MC/DC50%1/2
exists $_[0]{"set"}{"method"} and $_[0]{"set"}{"method"} eq "until"
exists $_[0]{"set"}{"method"} $_[0]{"set"}{"method"} eq "until"
Truth table66%2/3
A and B
A= exists $_[0]{"set"}{"method"}B= $_[0]{"set"}{"method"} eq "until"
ABresult
0X0
100
111
186 $_[0]->{set}{method} eq 'until' )
187 {
188 5 return bless { set => $_[0]->{set}{parent}[1] }, 'DateTime::Set';
189 }
190 2 my $return = DateTime::Set->empty_set;
191 2 $return->{set} = $_[0]->{set}->end_set;
192 2 $return;
193 }
194  
195 34 ▶sub empty_set {
Subroutine empty_set: called CC=1 SCAR=0.0
Pod documented
196 34 my $class = shift;
197  
198 34 return bless { set => Set::Infinite::_recurrence->new }, $class;
199 }
200  
201 0 ▶sub is_empty_set {
Subroutine is_empty_set: not called CC=1 SCAR=6.9
Pod documented
202 0 my $set = $_[0];
203 0 $set->{set}->is_null;
204 }
205  
206 9 ▶sub clone {
Subroutine clone: called CC=1 SCAR=0.0
Pod documented
207 bless {
208 set => $_[0]->{set}->copy,
209 9 }, ref $_[0];
210 }
211  
212  
213 12 ▶sub iterator {
Subroutine iterator: called CC=3 SCAR=11.0
Pod documented
214 12 my $self = shift;
215  
216 12 my %args = @_;
217 12 my $span;
218 12 $span = delete $args{span};
219 12 ▶ $span = DateTime::Span->new( %args ) if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 1 11 12
220  
221 12 ▶ return $self->intersection( $span ) if $span;
Branch: 1 branch
BranchTrueFalseTotal
if $span 4 8 12
222 8 return $self->clone;
223 }
224  
225  
226 # next() gets the next element from an iterator()
227 48 ▶sub next {
Subroutine next: called CC=10 SCAR=23.3
Pod documented
228 48 my ($self) = shift;
229  
230 # TODO: this is fixing an error from elsewhere
231 # - find out what's going on! (with "sunset.pl")
232 48 ▶ return undef unless ref $self->{set};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"set"} 3 45 48
233  
234 45 ▶ if ( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 39 45
235 {
236 6 my $max;
237 6 ▶ $max = $_[0]->max if UNIVERSAL::can( $_[0], 'union' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_[0], "union") 1 5 6
238 6 ▶ $max = $_[0] if ! defined $max;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $max 5 1 6
239  
240 6 ▶ return undef if ! ref( $max ) && $max == INFINITY;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $max and $max == "Inf" 0 6 6
Condition33%1/3
not ref $max and $max == "Inf"
!ll&&!rl&&r
600
MC/DC0%0/2
not ref $max and $max == "Inf"
not ref $max $max == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $maxB= $max == "Inf"
ABresult
0X0
100
111
241  
242 6 my $span = DateTime::Span->from_datetimes( start => $max );
243 6 my $iterator = $self->intersection( $span );
244 6 my $return = $iterator->next;
245  
246 6 ▶ return $return if ! defined $return;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 6 6
247 6 ▶ return $return if ! $return->intersects( $max );
Branch: 1 branch
BranchTrueFalseTotal
unless $return->intersects($max) 5 1 6
248  
249 1 return $iterator->next;
250 }
251  
252 39 my ($head, $tail) = $self->{set}->first;
253 39 $self->{set} = $tail;
254 39 ▶ return $head unless ref $head;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $head 0 39 39
255 39 my $return = {
256 set => $head,
257 };
258 39 bless $return, 'DateTime::Span';
259 39 return $return;
260 }
261  
262 # previous() gets the last element from an iterator()
263 17 ▶sub previous {
Subroutine previous: called CC=10 SCAR=23.3
Pod documented
264 17 my ($self) = shift;
265  
266 17 ▶ return undef unless ref $self->{set};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"set"} 2 15 17
267  
268 15 ▶ if ( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 12 15
269 {
270 3 my $min;
271 3 ▶ $min = $_[0]->min if UNIVERSAL::can( $_[0], 'union' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_[0], "union") 1 2 3
272 3 ▶ $min = $_[0] if ! defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 2 1 3
273  
274 3 ▶ return undef if ! ref( $min ) && $min == INFINITY;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $min and $min == "Inf" 0 3 3
Condition33%1/3
not ref $min and $min == "Inf"
!ll&&!rl&&r
300
MC/DC0%0/2
not ref $min and $min == "Inf"
not ref $min $min == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $minB= $min == "Inf"
ABresult
0X0
100
111
275  
276 3 my $span = DateTime::Span->from_datetimes( end => $min );
277 3 my $iterator = $self->intersection( $span );
278 3 my $return = $iterator->previous;
279  
280 3 ▶ return $return if ! defined $return;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return 0 3 3
281 3 ▶ return $return if ! $return->intersects( $min );
Branch: 1 branch
BranchTrueFalseTotal
unless $return->intersects($min) 1 2 3
282  
283 2 return $iterator->previous;
284 }
285  
286 12 my ($head, $tail) = $self->{set}->last;
287 12 $self->{set} = $tail;
288 12 ▶ return $head unless ref $head;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $head 0 12 12
289 12 my $return = {
290 set => $head,
291 };
292 12 bless $return, 'DateTime::Span';
293 12 return $return;
294 }
295  
296 # "current" means less-or-equal to a DateTime
297 4 ▶sub current {
Subroutine current: called CC=9 SCAR=22.9
Pod documented
298 4 my $self = shift;
299  
300 4 my $previous;
301 my $next;
302 {
303 4 my $min;
304 4 ▶ $min = $_[0]->min if UNIVERSAL::can( $_[0], 'union' );
Branch: 1 branch
BranchTrueFalseTotal
if UNIVERSAL::can($_[0], "union") 0 4 4
305 4 ▶ $min = $_[0] if ! defined $min;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $min 4 0 4
306 4 ▶ return undef if ! ref( $min ) && $min == INFINITY;
Branch: 1 branch
BranchTrueFalseTotal
if not ref $min and $min == "Inf" 0 4 4
Condition33%1/3
not ref $min and $min == "Inf"
!ll&&!rl&&r
400
MC/DC0%0/2
not ref $min and $min == "Inf"
not ref $min $min == "Inf"
Truth table33%1/3
not(A) and B
A= not ref $minB= $min == "Inf"
ABresult
0X0
100
111
307 4 my $span = DateTime::Span->from_datetimes( end => $min );
308 4 my $iterator = $self->intersection( $span );
309 4 $previous = $iterator->previous;
310 4 $span = DateTime::Span->from_datetimes( start => $min );
311 4 $iterator = $self->intersection( $span );
312 4 $next = $iterator->next;
313 }
314 4 ▶ return $previous unless defined $next;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $next 0 4 4
315  
316 4 ▶ my $dt1 = defined $previous
Branch: 1 branch
BranchTrueFalseTotal
defined $previous ? : 4 0 4
317 ? $next->union( $previous )
318 : $next;
319  
320 4 my $return = $dt1->intersected_spans( $_[0] );
321  
322 4 ▶ $return = $previous
Branch: 1 branch
BranchTrueFalseTotal
unless defined $return->max 2 2 4
323 if !defined $return->max;
324  
325 4 ▶ bless $return, 'DateTime::SpanSet'
Branch: 1 branch
BranchTrueFalseTotal
if defined $return 4 0 4
326 if defined $return;
327 4 return $return;
328 }
329  
330 3 ▶sub closest {
Subroutine closest: called CC=7 SCAR=19.6
Pod documented
331 3 my $self = shift;
332 3 my $dt = shift;
333  
334 3 my $dt1 = $self->current( $dt );
335 3 my $dt2 = $self->next( $dt );
336 3 ▶ bless $dt2, 'DateTime::SpanSet'
Branch: 1 branch
BranchTrueFalseTotal
if defined $dt2 2 1 3
337 if defined $dt2;
338  
339 3 ▶ return $dt2 unless defined $dt1;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt1 0 3 3
340 3 ▶ return $dt1 unless defined $dt2;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dt2 1 2 3
341  
342 2 ▶ $dt = DateTime::Set->from_datetimes( dates => [ $dt ] )
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::can($dt, "union") 2 0 2
343 unless UNIVERSAL::can( $dt, 'union' );
344  
345 2 ▶ return $dt1 if $dt1->contains( $dt );
Branch: 1 branch
BranchTrueFalseTotal
if $dt1->contains($dt) 0 2 2
346  
347 2 my $delta = $dt->min - $dt1->max;
348 2 ▶ return $dt1 if ( $dt2->min - $delta ) >= $dt->max;
Branch: 1 branch
BranchTrueFalseTotal
if $dt2->min - $delta >= $dt->max 1 1 2
349  
350 1 return $dt2;
351 }
352  
353 1 ▶sub as_list {
Subroutine as_list: called CC=7 SCAR=19.9
Pod documented
354 1 my $self = shift;
355 1 ▶ return undef unless ref( $self->{set} );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"set"} 0 1 1
356  
357 1 my %args = @_;
358 1 my $span;
359 1 $span = delete $args{span};
360 1 ▶ $span = DateTime::Span->new( %args ) if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 0 1 1
361  
362 1 my $set = $self->clone;
363 1 ▶ $set = $set->intersection( $span ) if $span;
Branch: 1 branch
BranchTrueFalseTotal
if $span 0 1 1
364  
365 # Note: removing this line means we may end up in an infinite loop!
366 1 ▶ return undef if $set->{set}->is_too_complex; # undef = no start/end
Branch: 1 branch
BranchTrueFalseTotal
if $set->{"set"}->is_too_complex 0 1 1
367  
368 # return if $set->{set}->is_null; # nothing = empty
369 1 my @result;
370 # we should extract _copies_ of the set elements,
371 # such that the user can't modify the set indirectly
372  
373 1 my $iter = $set->iterator;
374 1 ▶ while ( my $dt = $iter->next )
Branch: 1 branch
BranchTrueFalseTotal
if (my $dt = $iter->next) 3 1 4
375 {
376 3 ▶ push @result, $dt
Branch: 1 branch
BranchTrueFalseTotal
if ref $dt 3 0 3
377 if ref( $dt ); # we don't want to return INFINITY value
378 };
379  
380 1 return @result;
381 }
382  
383 # Set::Infinite methods
384  
385 22 ▶sub intersection {
Subroutine intersection: called CC=4 SCAR=14.2
Pod documented
386 22 my ($set1, $set2) = ( shift, shift );
387 22 my $class = ref($set1);
388 22 my $tmp = $class->empty_set();
389 22 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 22 22
390 if $set2->can( 'as_spanset' );
391 22 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 22 22
392 if $set2->can( 'as_set' );
393 22 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 0 22 22
394 unless $set2->can( 'union' );
395 22 $tmp->{set} = $set1->{set}->intersection( $set2->{set} );
396 22 return $tmp;
397 }
398  
399 5 ▶sub intersected_spans {
Subroutine intersected_spans: called CC=4 SCAR=14.2
Pod documented
400 5 my ($set1, $set2) = ( shift, shift );
401 5 my $class = ref($set1);
402 5 my $tmp = $class->empty_set();
403 5 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 5 5
404 if $set2->can( 'as_spanset' );
405 5 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 5 5
406 if $set2->can( 'as_set' );
407 5 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 5 0 5
408 unless $set2->can( 'union' );
409 5 $tmp->{set} = $set1->{set}->intersected_spans( $set2->{set} );
410 5 return $tmp;
411 }
412  
413 1 ▶sub intersects {
Subroutine intersects: called CC=7 SCAR=30.2
Pod documented
414 1 my ($set1, $set2) = ( shift, shift );
415
416 1 ▶ unless ( $set2->can( 'union' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($set2->can("union")) 1 0 1
417 {
418 1 for ( $set2, @_ )
419 {
420 1 ▶ return 1 if $set1->contains( $_ );
Branch: 1 branch
BranchTrueFalseTotal
if $set1->contains($_) 0 1 1
421 }
422 1 return 0;
423 }
424
425 0 my $class = ref($set1);
426 0 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 0 0
427 if $set2->can( 'as_spanset' );
428 0 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 0 0
429 if $set2->can( 'as_set' );
430 0 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 0 0 0
431 unless $set2->can( 'union' );
432 0 return $set1->{set}->intersects( $set2->{set} );
433 }
434  
435 6 ▶sub contains {
Subroutine contains: called CC=11 SCAR=25.9
Pod documented
436 6 my ($set1, $set2) = ( shift, shift );
437
438 6 ▶ unless ( $set2->can( 'union' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($set2->can("union")) 4 2 6
439 {
440 4 ▶ if ( exists $set1->{set}{method} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $set1->{"set"}{"method"} and $set1->{"set"}{"method"} eq "until") 4 0 4
Condition33%1/3
exists $set1->{"set"}{"method"} and $set1->{"set"}{"method"} eq "until"
!ll&&!rl&&r
004
MC/DC0%0/2
exists $set1->{"set"}{"method"} and $set1->{"set"}{"method"} eq "until"
exists $set1->{"set"}{"method"} $set1->{"set"}{"method"} eq "until"
Truth table33%1/3
A and B
A= exists $set1->{"set"}{"method"}B= $set1->{"set"}{"method"} eq "until"
ABresult
0X0
100
111
441 $set1->{set}{method} eq 'until' )
442 {
443 4 my $start_set = $set1->start_set;
444 4 my $end_set = $set1->end_set;
445  
446 4 for ( $set2, @_ )
447 {
448 4 my $start = $start_set->next( $set2 );
449 4 my $end = $end_set->next( $set2 );
450  
451 4 ▶ goto ABORT unless defined $start && defined $end;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $start and defined $end 0 4 4
Condition33%1/3
defined $start and defined $end
!ll&&!rl&&r
004
MC/DC0%0/2
defined $start and defined $end
defined $start defined $end
Truth table33%1/3
A and B
A= defined $startB= defined $end
ABresult
0X0
100
111
452
453 4 ▶ return 0 if $start < $end;
Branch: 1 branch
BranchTrueFalseTotal
if $start < $end 3 1 4
454 }
455 1 return 1;
456  
457 0 ABORT: ;
458 # don't know
459 }
460 }
461
462 2 my $class = ref($set1);
463 2 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 2 2
464 if $set2->can( 'as_spanset' );
465 2 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 2 2
466 if $set2->can( 'as_set' );
467 2 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 0 2 2
468 unless $set2->can( 'union' );
469 2 return $set1->{set}->contains( $set2->{set} );
470 }
471  
472 4 ▶sub union {
Subroutine union: called CC=4 SCAR=14.0
Pod documented
473 4 my ($set1, $set2) = ( shift, shift );
474 4 my $class = ref($set1);
475 4 my $tmp = $class->empty_set();
476 4 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 4 4
477 if $set2->can( 'as_spanset' );
478 4 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 4 4
479 if $set2->can( 'as_set' );
480 4 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 2 2 4
481 unless $set2->can( 'union' );
482 4 $tmp->{set} = $set1->{set}->union( $set2->{set} );
483 4 return $tmp;
484 }
485  
486 0 ▶sub complement {
Subroutine complement: not called CC=5 SCAR=34.0
Pod documented
487 0 my ($set1, $set2) = ( shift, shift );
488 0 my $class = ref($set1);
489 0 my $tmp = $class->empty_set();
490 0 ▶ if (defined $set2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $set2) { } 0 0 0
491 0 ▶ $set2 = $set2->as_spanset
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_spanset") 0 0 0
492 if $set2->can( 'as_spanset' );
493 0 ▶ $set2 = $set2->as_set
Branch: 1 branch
BranchTrueFalseTotal
if $set2->can("as_set") 0 0 0
494 if $set2->can( 'as_set' );
495 0 ▶ $set2 = DateTime::Set->from_datetimes( dates => [ $set2, @_ ] )
Branch: 1 branch
BranchTrueFalseTotal
unless $set2->can("union") 0 0 0
496 unless $set2->can( 'union' );
497 0 $tmp->{set} = $set1->{set}->complement( $set2->{set} );
498 }
499 else {
500 0 $tmp->{set} = $set1->{set}->complement;
501 }
502 0 return $tmp;
503 }
504  
505 16 ▶sub start {
Subroutine start: called CC=1 SCAR=0.0
Pod documented
506 16 return DateTime::Set::_fix_datetime( $_[0]->{set}->min );
507 }
508  
509 23 *min = \&start;
510  
511 20 ▶sub end {
Subroutine end: called CC=1 SCAR=0.0
Pod documented
512 20 return DateTime::Set::_fix_datetime( $_[0]->{set}->max );
513 }
514  
515 23 *max = \&end;
516  
517 # returns a DateTime::Span
518 0 ▶sub span {
Subroutine span: not called CC=1 SCAR=6.9
Pod documented
519 0 my $set = $_[0]->{set}->span;
520 0 my $self = bless { set => $set }, 'DateTime::Span';
521 0 return $self;
522 }
523  
524 # returns a DateTime::Duration
525 3 ▶sub duration {
Subroutine duration: called CC=4 SCAR=14.0
Pod documented
526 3 my $dur;
527  
528 return DateTime::Duration->new( seconds => 0 )
529 3 ▶ if $_[0]->{set}->is_empty;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"set"}->is_empty 1 2 3
530  
531 2 local $@;
532 2 eval {
533 2 local $SIG{__DIE__}; # don't want to trap this (rt ticket 5434)
534 $dur = $_[0]->{set}->size
535 2 };
536  
537 2 ▶ return $dur if defined $dur && ref( $dur );
Branch: 1 branch
BranchTrueFalseTotal
if defined $dur and ref $dur 0 2 2
Condition66%2/3
defined $dur and ref $dur
!ll&&!rl&&r
110
MC/DC0%0/2
defined $dur and ref $dur
defined $dur ref $dur
Truth table66%2/3
A and B
A= defined $durB= ref $dur
ABresult
0X0
100
111
538 2 return DateTime::Infinite::Future->new -
539 DateTime::Infinite::Past->new;
540 # return INFINITY;
541 }
542 23 *size = \&duration;
543  
544 23 1;
545  
546 __END__
« Set/Infinite/_recurrence.pm ↑ Summary DateTime/Span.pm »