blib/lib/DateTime/Event/Cron.pm

filter: Statementstmt 89.7% 383 / 427 Branchbran 79.6% 164 / 206 Conditioncond 57.8% 55 / 95 MC/DCmcdc 27.4% 14 / 51 Subroutinesub 86.0% 68 / 79 Podpod 66.6% 14 / 21 totaltotal 79.4% 698 / 879 CC 136 SCAR 23.1
CC
136
Cov
83%
new_from_crontab
42.0
match
30.0
_dump_sets
30.0
CRAP 10.1
↑ Summary
1 package DateTime::Event::Cron;
2  
3 7 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 7 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 $VERSION = '0.09';
11  
12 7 ▶use constant DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 7 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 7 ▶use DateTime::Set;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 7 ▶use DateTime::Duration;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 7 ▶use Set::Crontab;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 7 my %Object_Attributes;
20  
21 ###
22  
23 29 ▶sub from_cron {
Subroutine from_cron: called CC=3 SCAR=11.0
Pod documented
24 # Return cron as DateTime::Set
25 29 my $class = shift;
26 29 ▶ my %sparms = @_ == 1 ? (cron => shift) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 29 29
27 29 my %parms;
28 29 $parms{cron} = delete $sparms{cron};
29 29 $parms{user_mode} = delete $sparms{user_mode};
30 29 ▶ $parms{cron} or croak "Cron string parameter required.\n";
Branch: 1 branch
BranchTrueFalseTotal
$parms{"cron"} or croak("Cron string parameter required.\n") 27 2 29
31 27 my $dtc = $class->new(%parms);
32 22 $dtc->as_set(%sparms);
33 }
34  
35 1 ▶sub from_crontab {
Subroutine from_crontab: called CC=5 SCAR=16.1
Pod documented
36 # Return list of DateTime::Sets based on entries from
37 # a crontab file.
38 1 my $class = shift;
39 1 ▶ my %sparms = @_ == 1 ? (file => shift) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 1 1
40 1 my $file = delete $sparms{file};
41 1 delete $sparms{cron};
42 1 my $fh = $class->_prepare_fh($file);
43 1 my @cronsets;
44 1 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 11 1 12
45 11 chomp;
46 11 my $set;
47 11 eval { $set = $class->from_cron(%sparms, cron => $_) };
48 11 ▶ push(@cronsets, $set) if ref $set && !$@;
Branch: 1 branch
BranchTrueFalseTotal
if ref $set and not $@ 4 7 11
Condition66%2/3
ref $set and not $@
!ll&&!rl&&r
704
MC/DC50%1/2
ref $set and not $@
ref $set not $@
Truth table66%2/3
A and not(B)
A= ref $setB= not $@
ABresult
0X0
100
111
49 }
50 1 @cronsets;
51 }
52  
53 22 ▶sub as_set {
Subroutine as_set: called CC=4 SCAR=14.6
Pod documented
54 # Return self as DateTime::Set
55 22 my $self = shift;
56 22 my %sparms = @_;
57 Carp::cluck "Recurrence callbacks overriden by ". ref $self . "\n"
58 22 ▶ if $sparms{next} || $sparms{recurrence} || $sparms{previous};
Branch: 1 branch
BranchTrueFalseTotal
if $sparms{"next"} or $sparms{"recurrence"} or $sparms{"previous"} 0 22 22
Condition33%2/6
$sparms{"next"} or $sparms{"recurrence"} or $sparms{"previous"}
l!l&&r!l&&!r
0022
$sparms{"next"} or $sparms{"recurrence"}
l!l&&r!l&&!r
0022
MC/DC0%0/3
$sparms{"next"} or $sparms{"recurrence"} or $sparms{"previous"}
$sparms{"next"} $sparms{"recurrence"} $sparms{"previous"}
Truth table25%1/4
A or B or C
A= $sparms{"next"}B= $sparms{"recurrence"}C= $sparms{"previous"}
ABCresult
1XX1
01X1
0011
0000
59 22 delete $sparms{next};
60 22 delete $sparms{previous};
61 22 delete $sparms{recurrence};
62 22 ▶ $sparms{next} = sub { $self->next(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
63 22 ▶ $sparms{previous} = sub { $self->previous(@_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
64 22 DateTime::Set->from_recurrence(%sparms);
65 }
66  
67 ###
68  
69 54 ▶sub new {
Subroutine new: called CC=2 SCAR=6.9
Pod undocumented
70 54 my $class = shift;
71 54 my $self = {};
72 54 bless $self, $class;
73 54 ▶ my %parms = @_ == 1 ? (cron => shift) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 26 28 54
74 54 my $crontab = $self->_make_cronset(%parms);
75 33 $self->_cronset($crontab);
76 33 $self;
77 }
78  
79 7 ▶sub new_from_cron { new(@_) }
Subroutine new_from_cron: called CC=1 SCAR=0.0
Pod documented
80  
81 0 ▶sub new_from_crontab {
Subroutine new_from_crontab: not called CC=6 SCAR=37.4
Pod documented
82 0 my $class = shift;
83 0 ▶ my %parms = @_ == 1 ? (file => shift()) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
84 0 my $fh = $class->_prepare_fh($parms{file});
85 0 delete $parms{file};
86 0 my @dtcrons;
87 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
88 0 my $dtc;
89 0 eval { $dtc = $class->new(%parms, cron => $_) };
90 0 ▶ if (ref $dtc && !$@) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dtc and not $@) 0 0 0
Condition0%0/3
ref $dtc and not $@
!ll&&!rl&&r
000
MC/DC0%0/2
ref $dtc and not $@
ref $dtc not $@
Truth table0%0/3
A and not(B)
A= ref $dtcB= not $@
ABresult
0X0
100
111
91 0 push(@dtcrons, $dtc);
92 0 ▶ $parms{user_mode} = 1 if defined $dtc->user;
Branch: 1 branch
BranchTrueFalseTotal
if defined $dtc->user 0 0 0
93 }
94 }
95 0 @dtcrons;
96 }
97  
98 ###
99  
100 1 ▶sub _prepare_fh {
Subroutine _prepare_fh: called CC=3 SCAR=16.8
101 1 my $class = shift;
102 1 my $fh = shift;
103 1 ▶ if (! ref $fh) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $fh) 0 1 1
104 0 my $file = $fh;
105 0 local(*FH);
106 0 $fh = do { local *FH; *FH }; # doubled *FH avoids warning
107 0 ▶ open($fh, "<$file")
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<$file" or croak("Error opening $file for reading\n") 0 0 0
108 or croak "Error opening $file for reading\n";
109 }
110 1 $fh;
111 }
112  
113 ###
114  
115 444 ▶sub valid {
Subroutine valid: called CC=6 SCAR=17.9
Pod documented
116 # Is the given date valid according the current cron settings?
117 444 my($self, $date) = @_;
118 444 ▶ return if !$date || $date->second;
Branch: 1 branch
BranchTrueFalseTotal
if not $date or $date->second 12 432 444
Condition66%2/3
not $date or $date->second
l!l&&r!l&&!r
012432
MC/DC50%1/2
not $date or $date->second
not $date $date->second
Truth table66%2/3
not(A) or B
A= not $dateB= $date->second
ABresult
1X1
011
000
119 432 ▶ $self->minute->contains($date->minute) &&
Branch: 1 branch
BranchTrueFalseTotal
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow) and $self->month->contains($date->month) 277 155 432
Condition100%6/6
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow)
!ll&&!rl&&r
13718277
$self->minute->contains($date->minute) and $self->hour->contains($date->hour)
!ll&&!rl&&r
11324295
MC/DC100%3/3
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow)
$self->minute->contains($date->minute) $self->hour->contains($date->hour) $self->days_contain($date->day, $date->dow)
Truth table100%4/4
A and B and C
A= $self->minute->contains($date->minute)B= $self->hour->contains($date->hour)C= $self->days_contain($date->day, $date->dow)
ABCresult
0XX0
10X0
1100
1111
120 $self->hour->contains($date->hour) &&
121 $self->days_contain($date->day, $date->dow) &&
122 $self->month->contains($date->month);
123 }
124  
125 0 ▶sub match {
Subroutine match: not called CC=5 SCAR=34.0
Pod documented
126 # Does the given date match the cron spec?
127 0 my($self, $date) = @_;
128 0 ▶ $date = DateTime->now unless $date;
Branch: 1 branch
BranchTrueFalseTotal
unless $date 0 0 0
129 0 ▶ $self->minute->contains($date->minute) &&
Branch: 1 branch
BranchTrueFalseTotal
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow) and $self->month->contains($date->month) 0 0 0
Condition0%0/6
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow)
!ll&&!rl&&r
000
$self->minute->contains($date->minute) and $self->hour->contains($date->hour)
!ll&&!rl&&r
000
MC/DC0%0/3
$self->minute->contains($date->minute) and $self->hour->contains($date->hour) and $self->days_contain($date->day, $date->dow)
$self->minute->contains($date->minute) $self->hour->contains($date->hour) $self->days_contain($date->day, $date->dow)
Truth table0%0/4
A and B and C
A= $self->minute->contains($date->minute)B= $self->hour->contains($date->hour)C= $self->days_contain($date->day, $date->dow)
ABCresult
0XX0
10X0
1100
1111
130 $self->hour->contains($date->hour) &&
131 $self->days_contain($date->day, $date->dow) &&
132 $self->month->contains($date->month);
133 }
134  
135 ### Return adjacent dates without altering original date
136  
137 99 ▶sub next {
Subroutine next: called CC=2 SCAR=7.1
Pod documented
138 99 my($self, $date) = @_;
139 99 ▶ $self->increment($date || DateTime->now);
Condition66%2/3
$date || 'DateTime'->now
l!l&&r!l&&!r
9810
MC/DC0%0/2
$date || 'DateTime'->now
$date 'DateTime'->now
Truth table66%2/3
A || B
A= $dateB= 'DateTime'->now
ABresult
1X1
011
000
140 }
141  
142 81 ▶sub previous {
Subroutine previous: called CC=2 SCAR=7.1
Pod documented
143 81 my($self, $date) = @_;
144 81 ▶ $self->decrement($date || DateTime->now);
Condition66%2/3
$date || 'DateTime'->now
l!l&&r!l&&!r
8010
MC/DC0%0/2
$date || 'DateTime'->now
$date 'DateTime'->now
Truth table66%2/3
A || B
A= $dateB= 'DateTime'->now
ABresult
1X1
011
000
145 }
146  
147 ### Change given date to adjacent dates
148  
149 99 ▶sub increment {
Subroutine increment: called CC=4 SCAR=13.9
Pod documented
150 99 my($self, $date) = @_;
151 99 ▶ $date = $date ? $date->clone : DateTime->now;
Branch: 1 branch
BranchTrueFalseTotal
$date ? : 99 0 99
152 99 ▶ return $date if $date->is_infinite;
Branch: 1 branch
BranchTrueFalseTotal
if $date->is_infinite 22 77 99
153 77 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->valid($date) or do { do { $self->_attempt_increment($date) } } 77 1 78
154 78 $self->_attempt_increment($date);
155 } until $self->valid($date);
156 77 $date;
157 }
158  
159 81 ▶sub decrement {
Subroutine decrement: called CC=4 SCAR=14.0
Pod documented
160 81 my($self, $date) = @_;
161 81 ▶ $date = $date ? $date->clone : DateTime->now;
Branch: 1 branch
BranchTrueFalseTotal
$date ? : 81 0 81
162 81 ▶ return $date if $date->is_infinite;
Branch: 1 branch
BranchTrueFalseTotal
if $date->is_infinite 22 59 81
163 59 ▶ do {
Branch: 1 branch
BranchTrueFalseTotal
$self->valid($date) or do { do { $self->_attempt_decrement($date) } } 59 0 59
164 59 $self->_attempt_decrement($date);
165 } until $self->valid($date);
166 59 $date;
167 }
168  
169 ###
170  
171 78 ▶sub _attempt_increment {
Subroutine _attempt_increment: called CC=3 SCAR=11.1
172 78 my($self, $date) = @_;
173 78 ▶ ref $date or croak "Reference to datetime object reqired\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $date or croak("Reference to datetime object reqired\n") 78 0 78
174 78 ▶ $self->valid($date) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->valid($date) ? : 50 28 78
175 $self->_valid_incr($date) :
176 $self->_invalid_incr($date);
177 }
178  
179 59 ▶sub _attempt_decrement {
Subroutine _attempt_decrement: called CC=3 SCAR=11.1
180 59 my($self, $date) = @_;
181 59 ▶ ref $date or croak "Reference to datetime object reqired\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $date or croak("Reference to datetime object reqired\n") 59 0 59
182 59 ▶ $self->valid($date) ?
Branch: 1 branch
BranchTrueFalseTotal
$self->valid($date) ? : 36 23 59
183 $self->_valid_decr($date) :
184 $self->_invalid_decr($date);
185 }
186  
187 50 ▶sub _valid_incr { shift->_incr(@_) }
Subroutine _valid_incr: called CC=1 SCAR=0.0
188  
189 36 ▶sub _valid_decr { shift->_decr(@_) }
Subroutine _valid_decr: called CC=1 SCAR=0.0
190  
191 28 ▶sub _invalid_incr {
Subroutine _invalid_incr: called CC=18 SCAR=29.1
192 # If provided date is valid, return it. Otherwise return
193 # nearest valid date after provided date.
194 28 my($self, $date) = @_;
195 28 ▶ ref $date or croak "Reference to datetime object reqired\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $date or croak("Reference to datetime object reqired\n") 28 0 28
196  
197 28 print STDERR "\nI GOT: ", $date->datetime, "\n" if DEBUG;
198  
199 28 ▶ $date->truncate(to => 'minute')->add(minutes => 1)
Branch: 1 branch
BranchTrueFalseTotal
if $date->second 8 20 28
200 if $date->second;
201  
202 28 print STDERR "RND: ", $date->datetime, "\n" if DEBUG;
203  
204 # Find our greatest invalid unit and clip
205 28 ▶ if (!$self->month->contains($date->month)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $self->month->contains($date->month)) { } 3 25 28
elsif (not $self->days_contain($date->day, $date->dow)) { } 12 13 25
elsif (not $self->hour->contains($date->hour)) { } 5 8 13
206 3 $date->truncate(to => 'month');
207 }
208 elsif (!$self->days_contain($date->day, $date->dow)) {
209 12 $date->truncate(to => 'day');
210 }
211 elsif (!$self->hour->contains($date->hour)) {
212 5 $date->truncate(to => 'hour');
213 }
214 else {
215 8 $date->truncate(to => 'minute');
216 }
217  
218 28 print STDERR "BBT: ", $date->datetime, "\n" if DEBUG;
219  
220 28 ▶ return $date if $self->valid($date);
Branch: 1 branch
BranchTrueFalseTotal
if $self->valid($date) 3 25 28
221  
222 25 print STDERR "ZZT: ", $date->datetime, "\n" if DEBUG;
223  
224 # Extraneous durations clipped. Start searching.
225 25 ▶ while (!$self->valid($date)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->valid($date)) 40 25 65
226 40 ▶ $date->add(months => 1) until $self->month->contains($date->month);
Branch: 1 branch
BranchTrueFalseTotal
$self->month->contains($date->month) or do { $date->add("months", 1) } 40 31 71
227 40 print STDERR "MON: ", $date->datetime, "\n" if DEBUG;
228  
229 40 my $day_orig = $date->day;
230 40 ▶ $date->add(days => 1) until $self->days_contain($date->day, $date->dow);
Branch: 1 branch
BranchTrueFalseTotal
$self->days_contain($date->day, $date->dow) or do { $date->add("days", 1) } 40 270 310
231 40 ▶ $date->truncate(to => 'month') && next if $date->day < $day_orig;
Branch: 1 branch
BranchTrueFalseTotal
if $date->day < $day_orig 5 35 40
Condition60%3/5
$date->day < $day_orig && ($date->truncate('to', 'month') && (next))
!ll&&!rl&&r
3550
$date->truncate("to", "month") and next
!ll
05
MC/DC0%0/2
$date->day < $day_orig && ($date->truncate('to', 'month') && (next))
$date->day < $day_orig $date->truncate("to", "month")
Truth table33%1/3
A && B
A= $date->day < $day_origB= $date->truncate("to", "month")
ABresult
0X0
100
111
232 35 print STDERR "DAY: ", $date->datetime, "\n" if DEBUG;
233  
234 35 my $hour_orig = $date->hour;
235 35 ▶ $date->add(hours => 1) until $self->hour->contains($date->hour);
Branch: 1 branch
BranchTrueFalseTotal
$self->hour->contains($date->hour) or do { $date->add("hours", 1) } 35 279 314
236 35 ▶ $date->truncate(to => 'day') && next if $date->hour < $hour_orig;
Branch: 1 branch
BranchTrueFalseTotal
if $date->hour < $hour_orig 5 30 35
Condition60%3/5
$date->hour < $hour_orig && ($date->truncate('to', 'day') && (next))
!ll&&!rl&&r
3050
$date->truncate("to", "day") and next
!ll
05
MC/DC0%0/2
$date->hour < $hour_orig && ($date->truncate('to', 'day') && (next))
$date->hour < $hour_orig $date->truncate("to", "day")
Truth table33%1/3
A && B
A= $date->hour < $hour_origB= $date->truncate("to", "day")
ABresult
0X0
100
111
237 30 print STDERR "HOR: ", $date->datetime, "\n" if DEBUG;
238  
239 30 my $min_orig = $date->minute;
240 30 ▶ $date->add(minutes => 1) until $self->minute->contains($date->minute);
Branch: 1 branch
BranchTrueFalseTotal
$self->minute->contains($date->minute) or do { $date->add("minutes", 1) } 30 480 510
241 30 ▶ $date->truncate(to => 'hour') && next if $date->minute < $min_orig;
Branch: 1 branch
BranchTrueFalseTotal
if $date->minute < $min_orig 5 25 30
Condition60%3/5
$date->minute < $min_orig && ($date->truncate('to', 'hour') && (next))
!ll&&!rl&&r
2550
$date->truncate("to", "hour") and next
!ll
05
MC/DC0%0/2
$date->minute < $min_orig && ($date->truncate('to', 'hour') && (next))
$date->minute < $min_orig $date->truncate("to", "hour")
Truth table33%1/3
A && B
A= $date->minute < $min_origB= $date->truncate("to", "hour")
ABresult
0X0
100
111
242 25 print STDERR "MIN: ", $date->datetime, "\n" if DEBUG;
243 }
244 25 print STDERR "SET: ", $date->datetime, "\n" if DEBUG;
245 25 $date;
246 }
247  
248 23 ▶sub _invalid_decr {
Subroutine _invalid_decr: called CC=21 SCAR=30.6
249 # If provided date is valid, return it. Otherwise
250 # return the nearest previous valid date.
251 23 my($self, $date) = @_;
252 23 ▶ ref $date or croak "Reference to datetime object reqired\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $date or croak("Reference to datetime object reqired\n") 23 0 23
253  
254 23 print STDERR "\nD GOT: ", $date->datetime, "\n" if DEBUG;
255  
256 23 ▶ if (!$self->month->contains($date->month)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $self->month->contains($date->month)) { } 3 20 23
elsif (not $self->days_contain($date->day, $date->dow)) { } 10 10 20
elsif (not $self->hour->contains($date->hour)) { } 3 7 10
257 3 $date->truncate(to => 'month');
258 }
259 elsif (!$self->days_contain($date->day, $date->dow)) {
260 10 $date->truncate(to => 'day');
261 }
262 elsif (!$self->hour->contains($date->hour)) {
263 3 $date->truncate(to => 'hour');
264 }
265 else {
266 7 $date->truncate(to => 'minute');
267 }
268  
269 23 print STDERR "BBT: ", $date->datetime, "\n" if DEBUG;
270  
271 23 ▶ return $date if $self->valid($date);
Branch: 1 branch
BranchTrueFalseTotal
if $self->valid($date) 3 20 23
272  
273 20 print STDERR "ZZT: ", $date->datetime, "\n" if DEBUG;
274  
275 # Extraneous durations clipped. Start searching.
276 20 ▶ while (!$self->valid($date)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->valid($date)) 34 20 54
277 34 ▶ if (!$self->month->contains($date->month)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->month->contains($date->month)) 9 25 34
278 9 ▶ $date->subtract(months => 1) until $self->month->contains($date->month);
Branch: 1 branch
BranchTrueFalseTotal
$self->month->contains($date->month) or do { $date->subtract("months", 1) } 9 62 71
279 9 $self->_unit_peak($date, 'month');
280 9 print STDERR "MON: ", $date->datetime, "\n" if DEBUG;
281 }
282 34 ▶ if (!$self->days_contain($date->day, $date->dow)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->days_contain($date->day, $date->dow)) 22 12 34
283 22 my $day_orig = $date->day;
284 22 ▶ $date->subtract(days => 1)
Branch: 1 branch
BranchTrueFalseTotal
$self->days_contain($date->day, $date->dow) or do { $date->subtract("days", 1) } 22 281 303
285 until $self->days_contain($date->day, $date->dow);
286 22 ▶ $self->_unit_peak($date, 'month') && next if ($date->day > $day_orig);
Branch: 1 branch
BranchTrueFalseTotal
if $date->day > $day_orig 9 13 22
Condition60%3/5
$date->day > $day_orig && ($self->_unit_peak($date, 'month') && (next))
!ll&&!rl&&r
1390
$self->_unit_peak($date, "month") and next
!ll
09
MC/DC0%0/2
$date->day > $day_orig && ($self->_unit_peak($date, 'month') && (next))
$date->day > $day_orig $self->_unit_peak($date, "month")
Truth table33%1/3
A && B
A= $date->day > $day_origB= $self->_unit_peak($date, "month")
ABresult
0X0
100
111
287 13 $self->_unit_peak($date, 'day');
288 13 print STDERR "DAY: ", $date->datetime, "\n" if DEBUG;
289 }
290 25 ▶ if (!$self->hour->contains($date->hour)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hour->contains($date->hour)) 21 4 25
291 21 my $hour_orig = $date->hour;
292 21 ▶ $date->subtract(hours => 1) until $self->hour->contains($date->hour);
Branch: 1 branch
BranchTrueFalseTotal
$self->hour->contains($date->hour) or do { $date->subtract("hours", 1) } 21 281 302
293 21 ▶ $self->_unit_peak($date, 'day') && next if ($date->hour > $hour_orig);
Branch: 1 branch
BranchTrueFalseTotal
if $date->hour > $hour_orig 3 18 21
Condition60%3/5
$date->hour > $hour_orig && ($self->_unit_peak($date, 'day') && (next))
!ll&&!rl&&r
1830
$self->_unit_peak($date, "day") and next
!ll
03
MC/DC0%0/2
$date->hour > $hour_orig && ($self->_unit_peak($date, 'day') && (next))
$date->hour > $hour_orig $self->_unit_peak($date, "day")
Truth table33%1/3
A && B
A= $date->hour > $hour_origB= $self->_unit_peak($date, "day")
ABresult
0X0
100
111
294 18 $self->_unit_peak($date, 'hour');
295 18 print STDERR "HOR: ", $date->datetime, "\n" if DEBUG;
296 }
297 22 ▶ if (!$self->minute->contains($date->minute)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->minute->contains($date->minute)) 22 0 22
298 22 my $min_orig = $date->minute;
299 22 ▶ $date->subtract(minutes => 1)
Branch: 1 branch
BranchTrueFalseTotal
$self->minute->contains($date->minute) or do { $date->subtract("minutes", 1) } 22 997 1019
300 until $self->minute->contains($date->minute);
301 22 ▶ $self->_unit_peak($date, 'hour') && next if ($date->minute > $min_orig);
Branch: 1 branch
BranchTrueFalseTotal
if $date->minute > $min_orig 2 20 22
Condition60%3/5
$date->minute > $min_orig && ($self->_unit_peak($date, 'hour') && (next))
!ll&&!rl&&r
2020
$self->_unit_peak($date, "hour") and next
!ll
02
MC/DC0%0/2
$date->minute > $min_orig && ($self->_unit_peak($date, 'hour') && (next))
$date->minute > $min_orig $self->_unit_peak($date, "hour")
Truth table33%1/3
A && B
A= $date->minute > $min_origB= $self->_unit_peak($date, "hour")
ABresult
0X0
100
111
302 20 print STDERR "MIN: ", $date->datetime, "\n" if DEBUG;
303 }
304 }
305 20 print STDERR "SET: ", $date->datetime, "\n" if DEBUG;
306 20 $date;
307 }
308  
309 ###
310  
311 54 ▶sub _unit_peak {
Subroutine _unit_peak: called CC=3 SCAR=12.5
312 54 my($self, $date, $unit) = @_;
313 54 ▶ $date && $unit or croak "DateTime ref and unit required.\n";
Branch: 1 branch
BranchTrueFalseTotal
$date and $unit or croak("DateTime ref and unit required.\n") 54 0 54
Condition33%1/3
$date and $unit
!ll&&!rl&&r
0054
MC/DC0%0/2
$date and $unit
$date $unit
Truth table33%1/3
A and B
A= $dateB= $unit
ABresult
0X0
100
111
314 54 $date->truncate(to => $unit)
315 ->add($unit . 's' => 1)
316 ->subtract(minutes => 1);
317 }
318  
319 40 ▶sub _next_day {
Subroutine _next_day: called CC=2 SCAR=6.9
320 40 my($self, $year, $mon, $day) = @_;
321 40 my $dt = DateTime->new(year => $year, month => $mon, day => $day);
322 32 my $dur = DateTime::Duration->new(days => 1);
323 32 $dt->add_duration($dur);
324 32 ▶ while (! $self->days_contain($dt->day, $dt->day_of_week)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->days_contain($dt->day, $dt->day_of_week)) 395 32 427
325 395 $dt->add_duration($dur);
326 }
327 32 $dt->day;
328 }
329  
330 31 ▶sub _prev_day {
Subroutine _prev_day: called CC=2 SCAR=6.9
331 31 my($self, $year, $mon, $day) = @_;
332 31 my $dt = DateTime->new(year => $year, month => $mon, day => $day);
333 24 my $dur = DateTime::Duration->new(days => 1);
334 24 $dt->subtract_duration($dur);
335 24 ▶ while (! $self->days_contain($dt->day, $dt->day_of_week)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->days_contain($dt->day, $dt->day_of_week)) 394 24 418
336 394 $dt->subtract_duration($dur);
337 }
338 24 $dt->day;
339 }
340  
341 ### Unit cascades
342  
343 50 ▶sub _incr {
Subroutine _incr: called CC=7 SCAR=19.5
344 50 my($self, $date) = @_;
345 50 my $last_min = $date->minute;
346 50 my $last_hour = $date->hour;
347 50 my $last_day = $date->day;
348 50 my $last_month = $date->month;
349 50 my $year = $date->year;
350 50 my($next_min, $next_hour, $next_day, $next_month) =
351 ($last_min, $last_hour, $last_day, $last_month);
352 50 while (1) {
353 72 $next_min = $self->minute->next($last_min);
354 72 ▶ if ($next_min <= $last_min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_min <= $last_min) 48 24 72
355 48 $next_hour = $self->hour->next($last_hour);
356 48 ▶ if ($next_hour <= $last_hour) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_hour <= $last_hour) 40 8 48
357 40 eval { $next_day = $self->_next_day($year, $last_month, $last_day) };
358 40 ▶ if ($next_day <= $last_day || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_day <= $last_day or $@) 19 21 40
Condition66%2/3
$next_day <= $last_day or $@
l!l&&r!l&&!r
19021
MC/DC50%1/2
$next_day <= $last_day or $@
$next_day <= $last_day $@
Truth table66%2/3
A or B
A= $next_day <= $last_dayB= $@
ABresult
1X1
011
000
359 19 $next_month = $self->month->next($last_month);
360 19 ▶ if ($next_month <= $last_month) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_month <= $last_month) 9 10 19
361 9 $year += 1;
362 }
363 19 $last_month = $next_month;
364 }
365 40 $last_day = $next_day;
366 }
367 48 $last_hour = $next_hour;
368 }
369 72 $last_min = $next_min;
370 72 eval {
371 72 $date->set(
372 minute => $next_min,
373 hour => $next_hour,
374 day => $next_day,
375 month => $next_month,
376 year => $year,
377 );
378 };
379 72 ▶ last unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 50 22 72
380 }
381 50 $date;
382 }
383  
384 36 ▶sub _decr {
Subroutine _decr: called CC=7 SCAR=19.5
385 36 my($self, $date) = @_;
386 36 my $last_min = $date->minute;
387 36 my $last_hour = $date->hour;
388 36 my $last_day = $date->day;
389 36 my $last_month = $date->month;
390 36 my $year = $date->year;
391 36 my($prev_min, $prev_hour, $prev_day, $prev_month) =
392 ($last_min, $last_hour, $last_day, $last_month);
393 36 while (1) {
394 68 $prev_min = $self->minute->previous($last_min);
395 68 ▶ if ($prev_min >= $last_min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_min >= $last_min) 43 25 68
396 43 $prev_hour = $self->hour->previous($last_hour);
397 43 ▶ if ($prev_hour >= $last_hour) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_hour >= $last_hour) 31 12 43
398 31 eval { $prev_day = $self->_prev_day($year, $last_month, $last_day) };
399 31 ▶ if ($prev_day >= $last_day || $@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_day >= $last_day or $@) 21 10 31
Condition66%2/3
$prev_day >= $last_day or $@
l!l&&r!l&&!r
21010
MC/DC50%1/2
$prev_day >= $last_day or $@
$prev_day >= $last_day $@
Truth table66%2/3
A or B
A= $prev_day >= $last_dayB= $@
ABresult
1X1
011
000
400 21 $prev_month = $self->month->previous($last_month);
401 21 ▶ if ($prev_month >= $last_month) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_month >= $last_month) 12 9 21
402 12 $year -= 1;
403 }
404 21 $last_month = $prev_month;
405 }
406 31 $last_day = $prev_day;
407 }
408 43 $last_hour = $prev_hour;
409 }
410 68 $last_min = $prev_min;
411 68 eval {
412 68 $date->set(
413 minute => $prev_min,
414 hour => $prev_hour,
415 day => $prev_day,
416 month => $prev_month,
417 year => $year,
418 );
419 };
420 68 ▶ last unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 36 32 68
421 }
422 36 $date;
423 }
424  
425 ### Factories
426  
427 54 ▶sub _make_cronset { shift; DateTime::Event::Cron::IntegratedSet->new(@_) }
Subroutine _make_cronset: called CC=1 SCAR=0.0
428  
429 ### Shortcuts
430  
431 1832 ▶sub days_contain { shift->_cronset->days_contain(@_) }
Subroutine days_contain: called CC=1 SCAR=0.0
Pod undocumented
432  
433 2123 ▶sub minute { shift->_cronset->minute }
Subroutine minute: called CC=1 SCAR=0.0
Pod undocumented
434 1074 ▶sub hour { shift->_cronset->hour }
Subroutine hour: called CC=1 SCAR=0.0
Pod undocumented
435 0 ▶sub dom { shift->_cronset->dom }
Subroutine dom: not called CC=1 SCAR=6.9
Pod undocumented
436 544 ▶sub month { shift->_cronset->month }
Subroutine month: called CC=1 SCAR=0.0
Pod undocumented
437 0 ▶sub dow { shift->_cronset->dow }
Subroutine dow: not called CC=1 SCAR=6.9
Pod undocumented
438 0 ▶sub user { shift->_cronset->user }
Subroutine user: not called CC=1 SCAR=6.9
Pod documented
439 0 ▶sub command { shift->_cronset->command }
Subroutine command: not called CC=1 SCAR=6.9
Pod documented
440 0 ▶sub original { shift->_cronset->original }
Subroutine original: not called CC=1 SCAR=6.9
Pod documented
441  
442 ### Static acessors/mutators
443  
444 5606 ▶sub _cronset { shift->_attr('cronset', @_) }
Subroutine _cronset: called CC=1 SCAR=0.0
445  
446 5606 ▶sub _attr {
Subroutine _attr: called CC=2 SCAR=6.9
447 5606 my $self = shift;
448 5606 my $name = shift;
449 5606 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 33 5573 5606
450 33 $Object_Attributes{$self}{$name} = shift;
451 }
452 5606 $Object_Attributes{$self}{$name};
453 }
454  
455 ### debugging
456  
457 0 ▶sub _dump_sets {
Subroutine _dump_sets: not called CC=5 SCAR=34.0
458 0 my($self, $date) = @_;
459 0 foreach (qw(minute hour dom month dow)) {
460 0 print STDERR "$_: ", join(',',$self->$_->list), "\n";
461 }
462 0 ▶ if (ref $date) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $date) 0 0 0
463 0 $date = $date->clone;
464 0 my @mod;
465 0 my $mon = $date->month;
466 0 $date->truncate(to => 'month');
467 0 ▶ while ($date->month == $mon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($date->month == $mon) 0 0 0
468 0 ▶ push(@mod, $date->day) if $self->days_contain($date->day, $date->dow);
Branch: 1 branch
BranchTrueFalseTotal
if $self->days_contain($date->day, $date->dow) 0 0 0
469 0 $date->add(days => 1);
470 }
471 0 print STDERR "mod for month($mon): ", join(',', @mod), "\n";
472 }
473 0 print STDERR "day_squelch: ", $self->_cronset->day_squelch, " ",
474 "dow_squelch: ", $self->_cronset->dow_squelch, "\n";
475 0 $self;
476 }
477  
478 ###
479  
480 54 ▶sub DESTROY { delete $Object_Attributes{shift()} }
Subroutine DESTROY: called CC=1 SCAR=0.0
481  
482 ##########
483  
484 {
485  
486 package DateTime::Event::Cron::IntegratedSet;
487  
488 # IntegratedSet manages the collection of field sets for
489 # each cron entry, including sanity checks. Individual
490 # field sets are accessed through their respective names,
491 # i.e., minute hour dom month dow.
492 #
493 # Also implements some merged field logic for dom/dow
494 # interactions.
495  
496 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
497 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
498  
499 7 my %Range = (
500 minute => [0..59],
501 hour => [0..23],
502 dom => [1..31],
503 month => [1..12],
504 dow => [1..7],
505 );
506  
507 7 my @Month_Max = qw( 31 29 31 30 31 30 31 31 30 31 30 31 );
508  
509 7 my %Object_Attributes;
510  
511 54 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
512 54 my $self = [];
513 54 bless $self, shift;
514 54 $self->_range(\%Range);
515 54 $self->set_cron(@_);
516 33 $self;
517 }
518  
519 54 ▶sub set_cron {
Subroutine set_cron: called CC=19 SCAR=29.5
520 # Initialize
521 54 my $self = shift;
522 54 my %parms = @_;
523 54 my $cron = $parms{cron};
524 54 my $user_mode = $parms{user_mode};
525 54 ▶ defined $cron or croak "Cron entry fields required\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $cron or croak("Cron entry fields required\n") 53 1 54
526 53 $self->_attr('original', $cron);
527 53 my @line;
528 53 ▶ if (ref $cron) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cron) { } 1 52 53
529 1 @line = grep(!/^\s*$/, @$cron);
530 }
531 else {
532 52 $cron =~ s/^\s+//;
533 52 $cron =~ s/\s+$//;
534 52 @line = split(/\s+/, $cron);
535 }
536 53 ▶ @line >= 5 or croak "At least five cron entry fields required.\n";
Branch: 1 branch
BranchTrueFalseTotal
@line >= 5 or croak("At least five cron entry fields required.\n") 44 9 53
537 44 my @entry = splice(@line, 0, 5);
538 44 my($user, $command);
539 44 ▶ unless (defined $user_mode) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user_mode) 44 0 44
540 # auto-detect
541 44 ▶ if (@line > 1 && $line[0] =~ /^\w+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@line > 1 and $line[0] =~ /^\w+$/) 4 40 44
Condition66%2/3
@line > 1 and $line[0] =~ /^\w+$/
!ll&&!rl&&r
4004
MC/DC50%1/2
@line > 1 and $line[0] =~ /^\w+$/
@line > 1 $line[0] =~ /^\w+$/
Truth table66%2/3
A and B
A= @line > 1B= $line[0] =~ /^\w+$/
ABresult
0X0
100
111
542 4 $user_mode = 1;
543 }
544 }
545 44 ▶ $user = shift @line if $user_mode;
Branch: 1 branch
BranchTrueFalseTotal
if $user_mode 4 40 44
546 44 $command = join(' ', @line);
547 44 $self->_attr('command', $command);
548 44 $self->_attr('user', $user);
549 44 my $i = 0;
550 44 foreach my $name (qw( minute hour dom month dow )) {
551 199 $self->_attr($name, $self->make_valid_set($name, $entry[$i]));
552 190 ++$i;
553 }
554 35 my @dom_list = $self->dom->list;
555 35 my @dow_list = $self->dow->list;
556 35 my $dom_range = $self->range('dom');
557 35 my $dow_range = $self->range('dow');
558 35 ▶ $self->dom_squelch(scalar @dom_list == scalar @$dom_range &&
Branch: 1 branch
BranchTrueFalseTotal
scalar @dom_list == scalar @$dom_range && scalar @dow_list != scalar @$dow_range ? : 6 29 35
Condition100%3/3
scalar @dom_list == scalar @$dom_range and scalar @dow_list != scalar @$dow_range
!ll&&!rl&&r
14156
MC/DC100%2/2
scalar @dom_list == scalar @$dom_range and scalar @dow_list != scalar @$dow_range
scalar @dom_list == scalar @$dom_range scalar @dow_list != scalar @$dow_range
Truth table100%3/3
A and B
A= scalar @dom_list == scalar @$dom_rangeB= scalar @dow_list != scalar @$dow_range
ABresult
0X0
100
111
559 scalar @dow_list != scalar @$dow_range ? 1 : 0);
560 35 ▶ $self->dow_squelch(scalar @dow_list == scalar @$dow_range &&
Branch: 1 branch
BranchTrueFalseTotal
scalar @dow_list == scalar @$dow_range && scalar @dom_list != scalar @$dom_range ? : 12 23 35
Condition100%3/3
scalar @dow_list == scalar @$dow_range and scalar @dom_list != scalar @$dom_range
!ll&&!rl&&r
81512
MC/DC100%2/2
scalar @dow_list == scalar @$dow_range and scalar @dom_list != scalar @$dom_range
scalar @dow_list == scalar @$dow_range scalar @dom_list != scalar @$dom_range
Truth table100%3/3
A and B
A= scalar @dow_list == scalar @$dow_rangeB= scalar @dom_list != scalar @$dom_range
ABresult
0X0
100
111
561 scalar @dom_list != scalar @$dom_range ? 1 : 0);
562 35 ▶ unless ($self->dom_squelch) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->dom_squelch) 29 6 35
563 29 my @doms = $self->dom->list;
564 29 my $pass = 0;
565 29 MONTH: foreach my $month ($self->month->list) {
566 33 foreach (@doms) {
567 33 ▶ ++$pass && last MONTH if $_ <= $Month_Max[$month - 1];
Branch: 1 branch
BranchTrueFalseTotal
if $_ <= $Month_Max[$month - 1] 27 6 33
Condition60%3/5
$_ <= $Month_Max[$month - 1] && (++$pass && (last MONTH))
!ll&&!rl&&r
6270
++$pass and last MONTH
!ll
027
MC/DC0%0/2
$_ <= $Month_Max[$month - 1] && (++$pass && (last MONTH))
$_ <= $Month_Max[$month - 1] ++$pass
Truth table33%1/3
A && B
A= $_ <= $Month_Max[$month - 1]B= ++$pass
ABresult
0X0
100
111
568 }
569 }
570 29 ▶ croak "Impossible last day for provided months.\n" unless $pass;
Branch: 1 branch
BranchTrueFalseTotal
unless $pass 2 27 29
571 }
572 33 $self;
573 }
574  
575 # Field range queries
576 269 ▶sub range {
Subroutine range: called CC=2 SCAR=7.1
577 269 my($self, $name) = @_;
578 269 ▶ my $val = $self->_range->{$name} or croak "Unknown field '$name'\n";
Branch: 1 branch
BranchTrueFalseTotal
my $val = $self->_range->{$name} or croak("Unknown field '${name}'\n") 269 0 269
579 269 $val;
580 }
581  
582 # Perform sanity checks when setting up each field set.
583 199 ▶sub make_valid_set {
Subroutine make_valid_set: called CC=7 SCAR=19.5
584 199 my($self, $name, $str) = @_;
585 199 my $range = $self->range($name);
586 199 my $set = $self->make_set($str, $range);
587 199 my @list = $set->list;
588 199 ▶ croak "Malformed cron field '$str'\n" unless @list;
Branch: 1 branch
BranchTrueFalseTotal
unless @list 2 197 199
589 197 ▶ croak "Field value ($list[-1]) out of range ($range->[0]-$range->[-1])\n"
Branch: 1 branch
BranchTrueFalseTotal
if $list[-1] > $range->[-1] 5 192 197
590 if $list[-1] > $range->[-1];
591 192 ▶ if ($name eq 'dow' && $set->contains(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "dow" and $set->contains(0)) 3 189 192
Condition100%3/3
$name eq "dow" and $set->contains(0)
!ll&&!rl&&r
157323
MC/DC100%2/2
$name eq "dow" and $set->contains(0)
$name eq "dow" $set->contains(0)
Truth table100%3/3
A and B
A= $name eq "dow"B= $set->contains(0)
ABresult
0X0
100
111
592 3 shift(@list);
593 3 ▶ push(@list, 7) unless $set->contains(7);
Branch: 1 branch
BranchTrueFalseTotal
unless $set->contains(7) 3 0 3
594 3 $set = $self->make_set(join(',',@list), $range);
595 }
596 192 ▶ croak "Field value ($list[0]) out of range ($range->[0]-$range->[-1])\n"
Branch: 1 branch
BranchTrueFalseTotal
if $list[0] < $range->[0] 2 190 192
597 if $list[0] < $range->[0];
598 190 $set;
599 }
600  
601 # No sanity checks
602 202 ▶sub make_set { shift; DateTime::Event::Cron::OrderedSet->new(@_) }
Subroutine make_set: called CC=1 SCAR=0.0
603  
604 # Flags for when dom/dow are applied.
605 1902 ▶sub dom_squelch { shift->_attr('dom_squelch', @_ ) }
Subroutine dom_squelch: called CC=1 SCAR=0.0
606 1694 ▶sub dow_squelch { shift->_attr('dow_squelch', @_ ) }
Subroutine dow_squelch: called CC=1 SCAR=0.0
607  
608 # Merged logic for dom/dow
609 1832 ▶sub days_contain {
Subroutine days_contain: called CC=6 SCAR=18.2
610 1832 my($self, $dom, $dow) = @_;
611 1832 ▶ defined $dom && defined $dow
Branch: 1 branch
BranchTrueFalseTotal
defined $dom and defined $dow or croak("Day of month and day of week required.\n") 1832 0 1832
Condition33%1/3
defined $dom and defined $dow
!ll&&!rl&&r
001832
MC/DC0%0/2
defined $dom and defined $dow
defined $dom defined $dow
Truth table33%1/3
A and B
A= defined $domB= defined $dow
ABresult
0X0
100
111
612 or croak "Day of month and day of week required.\n";
613 1832 my $dom_c = $self->dom->contains($dom);
614 1832 my $dow_c = $self->dow->contains($dow);
615 1832 ▶ return $dow_c if $self->dom_squelch;
Branch: 1 branch
BranchTrueFalseTotal
if $self->dom_squelch 173 1659 1832
616 1659 ▶ return $dom_c if $self->dow_squelch;
Branch: 1 branch
BranchTrueFalseTotal
if $self->dow_squelch 1390 269 1659
617 269 ▶ $dom_c || $dow_c;
Branch: 1 branch
BranchTrueFalseTotal
$dom_c or $dow_c 143 126 269
618 }
619  
620 # Set Accessors
621 2123 ▶sub minute { shift->_attr('minute' ) }
Subroutine minute: called CC=1 SCAR=0.0
622 1074 ▶sub hour { shift->_attr('hour' ) }
Subroutine hour: called CC=1 SCAR=0.0
623 1896 ▶sub dom { shift->_attr('dom' ) }
Subroutine dom: called CC=1 SCAR=0.0
624 573 ▶sub month { shift->_attr('month' ) }
Subroutine month: called CC=1 SCAR=0.0
625 1867 ▶sub dow { shift->_attr('dow' ) }
Subroutine dow: called CC=1 SCAR=0.0
626 0 ▶sub user { shift->_attr('user' ) }
Subroutine user: not called CC=1 SCAR=6.9
627 0 ▶sub command { shift->_attr('command') }
Subroutine command: not called CC=1 SCAR=6.9
628 0 ▶sub original { shift->_attr('original') }
Subroutine original: not called CC=1 SCAR=6.9
629  
630 # Accessors/mutators
631 323 ▶sub _range { shift->_attr('range', @_) }
Subroutine _range: called CC=1 SCAR=0.0
632  
633 11783 ▶sub _attr {
Subroutine _attr: called CC=2 SCAR=6.9
634 11783 my $self = shift;
635 11783 my $name = shift;
636 11783 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 455 11328 11783
637 455 $Object_Attributes{$self}{$name} = shift;
638 }
639 11783 $Object_Attributes{$self}{$name};
640 }
641  
642 54 ▶sub DESTROY { delete $Object_Attributes{shift()} }
Subroutine DESTROY: called CC=1 SCAR=0.0
643  
644 }
645  
646 ##########
647  
648 {
649  
650 7 package DateTime::Event::Cron::OrderedSet;
651  
652 # Extends Set::Crontab with some progression logic (next/prev)
653  
654 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
655 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
656 7 ▶use base 'Set::Crontab';
Subroutine BEGIN: called CC=1 SCAR=0.0
657  
658 7 my %Object_Attributes;
659  
660 202 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
661 202 my $class = shift;
662 202 my($string, $range) = @_;
663 202 ▶ defined $string && ref $range
Branch: 1 branch
BranchTrueFalseTotal
defined $string and ref $range or croak("Cron field and range ref required.\n") 202 0 202
Condition33%1/3
defined $string and ref $range
!ll&&!rl&&r
00202
MC/DC0%0/2
defined $string and ref $range
defined $string ref $range
Truth table33%1/3
A and B
A= defined $stringB= ref $range
ABresult
0X0
100
111
664 or croak "Cron field and range ref required.\n";
665 202 my $self = Set::Crontab->new($string, $range);
666 202 bless $self, $class;
667 202 my @list = $self->list;
668 202 my(%next, %prev);
669 202 foreach (0 .. $#list) {
670 2498 $next{$list[$_]} = $list[($_+1)%@list];
671 2498 $prev{$list[$_]} = $list[($_-1)%@list];
672 }
673 202 $self->_attr('next', \%next);
674 202 $self->_attr('previous', \%prev);
675 202 $self;
676 }
677  
678 139 ▶sub next {
Subroutine next: called CC=3 SCAR=11.3
679 139 my($self, $entry) = @_;
680 139 my $hash = $self->_attr('next');
681 139 ▶ croak "Missing entry($entry) in set\n" unless exists $hash->{$entry};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$entry} 0 139 139
682 139 my $next = $hash->{$entry};
683 139 ▶ wantarray ? ($next, $next <= $entry) : $next;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 139 139
684 }
685  
686 132 ▶sub previous {
Subroutine previous: called CC=3 SCAR=11.3
687 132 my($self, $entry) = @_;
688 132 my $hash = $self->_attr('previous');
689 132 ▶ croak "Missing entry($entry) in set\n" unless exists $hash->{$entry};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $hash->{$entry} 0 132 132
690 132 my $prev = $hash->{$entry};
691 132 ▶ wantarray ? ($prev, $prev >= $entry) : $prev;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 132 132
692 }
693  
694 675 ▶sub _attr {
Subroutine _attr: called CC=2 SCAR=6.9
695 675 my $self = shift;
696 675 my $name = shift;
697 675 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 404 271 675
698 404 $Object_Attributes{$self}{$name} = shift;
699 }
700 675 $Object_Attributes{$self}{$name};
701 }
702  
703 202 ▶sub DESTROY { delete $Object_Attributes{shift()} }
Subroutine DESTROY: called CC=1 SCAR=0.0
704  
705 }
706  
707 ###
708  
709 7 1;
710  
711 __END__
↑ Summary