| 1 | package Schedule::Cron::Events; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Set::Crontab; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Time::Local; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use vars qw($VERSION @monthlens); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | ($VERSION) = ('$Revision: 1.95 $' =~ /([\d\.]+)/ ); | |||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | @monthlens = ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ); | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | ## PUBLIC INTERFACE | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 32 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=19 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 32 | ▶ | my $cronline = shift || confess "You must supply a line from a crontab"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
shift() || confess('You must supply a line from a crontab')
MC/DC0%0/2
shift() || confess('You must supply a line from a crontab')
shift()
confess('You must supply a line from a crontab')
Truth table33%1/3
A || B
A= shift()B= confess('You must supply a line from a crontab')
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 32 | ▶ | if ($cronline =~ /^\s*#/) { return undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 30 | ▶ | if ($cronline =~ /^\w+=\S+/) { return undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 29 | ▶ | if ($cronline !~ /^\s*\S+\s+\S+\s+\S+\s+\S+\s+\S+/) { return undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # https://rt.cpan.org/Ticket/Display.html?id=53899 | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 27 | $cronline =~ s/^\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 27 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # 0 1 2 3 4 5 6 7 8 | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); | ||||||||||||||||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||||||||||||||||
| 29 | # $mday is the day of the month | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # $mon the month in the range 0..11, with 0 indicating | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # January and 11 indicating December. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # | ||||||||||||||||||||||||||||||||||||||||||
| 34 | # $year contains the number of years since 1900. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 27 | my @date; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | ▶ | if (exists $opts{'Seconds'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | @date = ( localtime($opts{'Seconds'}) )[0..5]; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } elsif (exists $opts{'Date'}) { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 26 | @date = @{ $opts{'Date'} }; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # input validation | ||||||||||||||||||||||||||||||||||||||||||
| 43 | # https://rt.cpan.org/Ticket/Display.html?id=68393 | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 26 | ▶ | if ($date[0] < 0 || $date[0] > 59) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date[0] < 0 or $date[0] > 59
MC/DC0%0/2
$date[0] < 0 or $date[0] > 59
$date[0] < 0
$date[0] > 59
Truth table33%1/3
A or B
A= $date[0] < 0B= $date[0] > 59
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | confess("Invalid value for seconds [" . $date[0] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 26 | ▶ | if ($date[1] < 0 || $date[1] > 59) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date[1] < 0 or $date[1] > 59
MC/DC0%0/2
$date[1] < 0 or $date[1] > 59
$date[1] < 0
$date[1] > 59
Truth table33%1/3
A or B
A= $date[1] < 0B= $date[1] > 59
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | confess("Invalid value for minutes [" . $date[1] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 26 | ▶ | if ($date[2] < 0 || $date[2] > 23) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date[2] < 0 or $date[2] > 23
MC/DC0%0/2
$date[2] < 0 or $date[2] > 23
$date[2] < 0
$date[2] > 23
Truth table33%1/3
A or B
A= $date[2] < 0B= $date[2] > 23
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | confess("Invalid value for hours [" . $date[2] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 26 | ▶ | if ($date[3] < 1 || $date[2] > 31) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date[3] < 1 or $date[2] > 31
MC/DC0%0/2
$date[3] < 1 or $date[2] > 31
$date[3] < 1
$date[2] > 31
Truth table33%1/3
A or B
A= $date[3] < 1B= $date[2] > 31
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | confess("Invalid value for day of month [" . $date[3] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | ▶ | if ($date[4] < 0 || $date[4] > 11) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$date[4] < 0 or $date[4] > 11
MC/DC0%0/2
$date[4] < 0 or $date[4] > 11
$date[4] < 0
$date[4] > 11
Truth table33%1/3
A or B
A= $date[4] < 0B= $date[4] > 11
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | confess("Month must be between 0 (January) and 11 (December), got [" . $date[4] . "]"); | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 26 | ▶ | if (time() < 2**31 && $date[5] > 137) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
time < 2147483648 and $date[5] > 137
MC/DC50%1/2
time < 2147483648 and $date[5] > 137
time < 2147483648
$date[5] > 137
Truth table66%2/3
A and B
A= time < 2147483648B= $date[5] > 137
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | confess("Year must be less than 137 (for example, if you need 2013 year, pass 113)"); | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | @date = ( localtime(time()) )[0..5]; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 26 | chomp($cronline); | |||||||||||||||||||||||||||||||||||||||||
| 67 | 26 | my %ranges = cronLineToRanges($cronline); | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 18 | my $self = { | |||||||||||||||||||||||||||||||||||||||||
| 70 | 'ranges' => \%ranges, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 'e' => [], # the set of possible months | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 'f' => [], # the set of possible days of the month, which varies (e.g. to omit day 31 in June, or to specify days by weekday) | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 'g' => [], # the set of possible hours | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 'h' => [], # the set of possible minutes | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 'pa' => 0, # pointer to which month we are 'currently' on, as far as the counter is concerned | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 'pb' => 0, # pointer to the day (actually the index of the current element) | ||||||||||||||||||||||||||||||||||||||||||
| 77 | 'pc' => 0, # pointer to the hour | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 'pd' => 0, # pointer to the minute | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 'pyear' => 0, # the 'current' year | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 'initdate' => \@date, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 'initline' => $cronline, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 'set_e_checked_years' => [], | ||||||||||||||||||||||||||||||||||||||||||
| 83 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # now fill the static sets with the sets from Set::Crontab | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 18 | @{ $self->{'e'} } = @{ $ranges{'months'} }; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 18 | @{ $self->{'g'} } = @{ $ranges{'hours'} }; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 18 | @{ $self->{'h'} } = @{ $ranges{'minutes'} }; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 18 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 18 | $self->resetCounter; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 18 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | sub resetCounter { | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 32 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resetCounter: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 32 | $self->setCounterToDate( @{$self->{'initdate'}} ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | sub nextEvent { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 70 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nextEvent: called CC=2 SCAR=7.4
Pod
documented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 70 | my @rv = $self->getdate(); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 70 | $self->inc_h(); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 70 | return @rv; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | sub previousEvent { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 42 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
previousEvent: called CC=2 SCAR=7.6
Pod
documented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 42 | $self->dec_h(); | |||||||||||||||||||||||||||||||||||||||||
| 110 | 42 | return $self->getdate(); | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | sub setCounterToNow { | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setCounterToNow: called CC=2 SCAR=8.1
Pod
documented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | $self->setCounterToDate( (localtime(time()))[0..5] ); | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub setCounterToDate { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 34 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setCounterToDate: called CC=11 SCAR=24.2
Pod
documented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 34 | ▶ | unless (@_ == 6) { confess "Must supply a 6-element date list"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # add a fudge factor of 60 seconds because cron events happen at the beginning of every minute, at the start of exactly seconds 00 | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 34 | my ($theMon, $theMday, $theHour, $theMin); | |||||||||||||||||||||||||||||||||||||||||
| 124 | 34 | (undef, $theMin, $theHour, $theMday, $theMon, $self->{'pyear'}) = (localtime(timelocal(@_) + 60))[0..5]; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 34 | $theMon++; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 34 | $self->{'pyear'} += 1900; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # nested ifs... to set the next occurrence time | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 34 | my ($exact, $pos) = contains($theMon, @{ $self->{'e'} }); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 34 | $self->{'pa'} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 34 | ▶ | if ($exact) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 30 | $self->set_f(); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 30 | ($exact, $pos) = contains($theMday, @{ $self->{'f'} }); | |||||||||||||||||||||||||||||||||||||||||
| 134 | 30 | $self->{'pb'} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 135 | 30 | ▶ | if ($exact) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 14 | ($exact, $pos) = contains($theHour, @{ $self->{'g'} }); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 14 | $self->{'pc'} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 14 | ▶ | if ($exact) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | ($exact, $pos) = contains($theMin, @{ $self->{'h'} }); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 11 | $self->{'pd'} = $pos; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 11 | ▶ | if ($pos == -1) { # search wrapped around | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 6 | $self->inc_h(); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | $self->{'pd'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | if ($pos == -1) { # search wrapped around | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $self->inc_g(); | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 16 | $self->{'pc'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 16 | $self->{'pd'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 16 | ▶ | if ($pos == -1) { # search wrapped around, maybe no valid days this month | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 6 | $self->inc_f(); | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | $self->{'pb'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 4 | $self->{'pc'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | $self->{'pd'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 4 | my $rv = $self->set_f(); | |||||||||||||||||||||||||||||||||||||||||
| 162 | 4 | ▶ | if ((! $rv) || ($pos == -1)) { # search wrapped around or no valid days this month, clock to the next month | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $rv or $pos == -1
MC/DC50%1/2
not $rv or $pos == -1
not $rv
$pos == -1
Truth table66%2/3
not(A) or B
A= not $rvB= $pos == -1
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | $self->inc_e(); | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | sub commandLine { | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commandLine: not called CC=2 SCAR=17.9
Pod
documented
Condition0%0/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table0%0/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return $self->{'ranges'}->{'execute'}; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | ## Internals only beyond this point | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | sub cronLineToRanges { | ||||||||||||||||||||||||||||||||||||||||||
| 177 | 26 | ▶ | my $line = shift || confess "Must supply a crontab line"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cronLineToRanges: called CC=29 SCAR=33.7
Pod
undocumented
Condition33%1/3
shift() || confess('Must supply a crontab line')
MC/DC0%0/2
shift() || confess('Must supply a crontab line')
shift()
confess('Must supply a crontab line')
Truth table33%1/3
A || B
A= shift()B= confess('Must supply a crontab line')
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 26 | my %ranges; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 26 | my @crondate = split(/\s+/, $line, 6); | |||||||||||||||||||||||||||||||||||||||||
| 181 | 26 | ▶ | if (@crondate < 5) { confess "Could not split the crontab line into enough fields"; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 26 | my $s = new Set::Crontab( $crondate[0], [0..59] ); | |||||||||||||||||||||||||||||||||||||||||
| 184 | 26 | $ranges{'minutes'} = [ $s->list() ]; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 26 | $s = new Set::Crontab( $crondate[1], [0..23] ); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 26 | $ranges{'hours'} = [ $s->list() ]; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 26 | $s = new Set::Crontab( $crondate[2], [0..31] ); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 26 | $ranges{'daynums'} = [ $s->list() ]; | |||||||||||||||||||||||||||||||||||||||||
| 191 | 26 | ▶ | if (@{ $ranges{'daynums'} } && ($ranges{'daynums'}->[0] == 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"daynums"};} and $ranges{"daynums"}[0] == 0
MC/DC100%2/2
@{$ranges{"daynums"};} and $ranges{"daynums"}[0] == 0
@{$ranges{"daynums"};}
$ranges{"daynums"}[0] == 0
Truth table100%3/3
A and B
A= @{$ranges{"daynums"};}B= $ranges{"daynums"}[0] == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 18 | shift @{ $ranges{'daynums'} }; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 26 | $s = new Set::Crontab( $crondate[3], [0..12] ); | |||||||||||||||||||||||||||||||||||||||||
| 196 | 26 | $ranges{'months'} = [ $s->list() ]; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 26 | ▶ | if (@{ $ranges{'months'} } && ($ranges{'months'}->[0] == 0)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"months"};} and $ranges{"months"}[0] == 0
MC/DC100%2/2
@{$ranges{"months"};} and $ranges{"months"}[0] == 0
@{$ranges{"months"};}
$ranges{"months"}[0] == 0
Truth table100%3/3
A and B
A= @{$ranges{"months"};}B= $ranges{"months"}[0] == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 22 | shift @{ $ranges{'months'} }; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 26 | $s = new Set::Crontab( $crondate[4], [0..7] ); | |||||||||||||||||||||||||||||||||||||||||
| 202 | 26 | $ranges{'weekdays'} = [ $s->list() ]; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 26 | ▶ | if (@{$ranges{'weekdays'}} && $ranges{'weekdays'}->[-1] == 7) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"weekdays"};} and $ranges{"weekdays"}[-1] == 7
MC/DC100%2/2
@{$ranges{"weekdays"};} and $ranges{"weekdays"}[-1] == 7
@{$ranges{"weekdays"};}
$ranges{"weekdays"}[-1] == 7
Truth table100%3/3
A and B
A= @{$ranges{"weekdays"};}B= $ranges{"weekdays"}[-1] == 7
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 19 | pop @{ $ranges{'weekdays'} }; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 19 | ▶ | if ((! @{ $ranges{'weekdays'} }) || $ranges{'weekdays'}->[0] != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not @{$ranges{"weekdays"};} or $ranges{"weekdays"}[0] != 0
MC/DC50%1/2
not @{$ranges{"weekdays"};} or $ranges{"weekdays"}[0] != 0
not @{$ranges{"weekdays"};}
$ranges{"weekdays"}[0] != 0
Truth table66%2/3
not(A) or B
A= not @{$ranges{"weekdays"};}B= $ranges{"weekdays"}[0] != 0
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | unshift @{ $ranges{'weekdays'} }, 0; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | # emulate cron's logic in determining which days to use | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 26 | ▶ | if ($crondate[2] ne '*' && $crondate[4] ne '*') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$crondate[2] ne "*" and $crondate[4] ne "*"
MC/DC100%2/2
$crondate[2] ne "*" and $crondate[4] ne "*"
$crondate[2] ne "*"
$crondate[4] ne "*"
Truth table100%3/3
A and B
A= $crondate[2] ne "*"B= $crondate[4] ne "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | # leave weekday and daynumber ranges alone, and superimpose | ||||||||||||||||||||||||||||||||||||||||||
| 213 | ▶ | } elsif ($crondate[2] eq '*' && $crondate[4] ne '*') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$crondate[2] eq "*" and $crondate[4] ne "*"
MC/DC100%2/2
$crondate[2] eq "*" and $crondate[4] ne "*"
$crondate[2] eq "*"
$crondate[4] ne "*"
Truth table100%3/3
A and B
A= $crondate[2] eq "*"B= $crondate[4] ne "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 5 | $ranges{'daynums'} = []; # restricted by weekday, not daynumber, so only use weekday range | |||||||||||||||||||||||||||||||||||||||||
| 215 | ▶ | } elsif ($crondate[4] eq '*' && $crondate[2] ne '*') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$crondate[4] eq "*" and $crondate[2] ne "*"
MC/DC50%1/2
$crondate[4] eq "*" and $crondate[2] ne "*"
$crondate[4] eq "*"
$crondate[2] ne "*"
Truth table66%2/3
A and B
A= $crondate[4] eq "*"B= $crondate[2] ne "*"
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 7 | $ranges{'weekdays'} = []; # restricted by daynumber, so only use daynumber range | |||||||||||||||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 11 | $ranges{'weekdays'} = []; # both are '*' so simply use every daynumber | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # check that ranges contain things | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 26 | foreach (qw(minutes hours months)) { | |||||||||||||||||||||||||||||||||||||||||
| 223 | 76 | ▶ | unless (@{ $ranges{$_} }) { confess "The $_ range must contain at least one valid value" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 24 | ▶ | unless (@{ $ranges{'weekdays'} } || @{ $ranges{'daynums'} }) { confess "The ranges of days (weekdays and monthdays) must contain at least one valid value" } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"weekdays"};} or @{$ranges{"daynums"};}
MC/DC100%2/2
@{$ranges{"weekdays"};} or @{$ranges{"daynums"};}
@{$ranges{"weekdays"};}
@{$ranges{"daynums"};}
Truth table100%3/3
A or B
A= @{$ranges{"weekdays"};}B= @{$ranges{"daynums"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | # sanity checking of ranges here, ensuring they only contain acceptable numbers | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 23 | ▶ | if ($ranges{'minutes'}[-1] > 59) { confess 'minutes only go up to 59'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 22 | ▶ | if ($ranges{'hours'}[-1] > 23) { confess 'hours only go up to 23'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 21 | ▶ | if ($ranges{'months'}[-1] > 12) { confess 'months only go up to 12'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 20 | ▶ | if (@{$ranges{'daynums'}} && $ranges{'daynums'}[-1] > 31) { confess 'daynumber must be 31 or less'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"daynums"};} and $ranges{"daynums"}[-1] > 31
MC/DC100%2/2
@{$ranges{"daynums"};} and $ranges{"daynums"}[-1] > 31
@{$ranges{"daynums"};}
$ranges{"daynums"}[-1] > 31
Truth table100%3/3
A and B
A= @{$ranges{"daynums"};}B= $ranges{"daynums"}[-1] > 31
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 19 | ▶ | if (@{$ranges{'weekdays'}} && $ranges{'weekdays'}[-1] > 6) { confess 'weekday too large - use 0 to 7'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@{$ranges{"weekdays"};} and $ranges{"weekdays"}[-1] > 6
MC/DC100%2/2
@{$ranges{"weekdays"};} and $ranges{"weekdays"}[-1] > 6
@{$ranges{"weekdays"};}
$ranges{"weekdays"}[-1] > 6
Truth table100%3/3
A and B
A= @{$ranges{"weekdays"};}B= $ranges{"weekdays"}[-1] > 6
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 18 | ▶ | $ranges{'execute'} = $crondate[5] || '#nothing'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$crondate[5] || '#nothing'
MC/DC100%1/1
$crondate[5] || '#nothing'
$crondate[5]
Truth table100%2/2
A
A= $crondate[5]
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | 18 | return %ranges; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | sub contains { | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 89 | ▶ | my ($val, @set) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 89 | my $flag = 0; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 89 | ▶ | while ($flag <= $#set) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 864 | ▶ | if ($set[$flag] == $val) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 60 | TRACE("contains: 1: $set[$flag] == $val"); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 60 | return 1, $flag; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } elsif ($set[$flag] > $val) { | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 15 | TRACE("contains: 0: $set[$flag] > $val"); | |||||||||||||||||||||||||||||||||||||||||
| 247 | 15 | return 0, $flag; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 789 | $flag++; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 14 | TRACE("contains: $val not found in <" . join(':', @set) . '>'); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 14 | return 0, -1; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | # return current date on the counter as seconds since epoch | ||||||||||||||||||||||||||||||||||||||||||
| 256 | sub getdate { | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 112 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getdate: called CC=2 SCAR=8.1
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 112 | return (0, $self->{'h'}[$self->{'pd'}], $self->{'g'}[$self->{'pc'}], $self->{'f'}[$self->{'pb'}], $self->{'e'}[$self->{'pa'}]-1, $self->{'pyear'}-1900); | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | # returns a list of days during which next event is possible | ||||||||||||||||||||||||||||||||||||||||||
| 262 | sub set_f { | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 102 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_f: called CC=9 SCAR=22.0
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 102 | my $flag = _isLeapYear($self->{'pyear'}); | |||||||||||||||||||||||||||||||||||||||||
| 266 | 102 | my $monthnum = $self->{'e'}[$self->{'pa'}]; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 102 | my $maxday = $monthlens[$monthnum]; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 102 | ▶ | if ($monthnum == 2) { $maxday += $flag; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 102 | my %days = map { $_ => 1 } @{ $self->{'ranges'}{'daynums'} }; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 102 | foreach (29, 30, 31) { | |||||||||||||||||||||||||||||||||||||||||
| 272 | 306 | ▶ | if ($_ > $maxday) { delete $days{$_}; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | # get which weekday is the first of the month | ||||||||||||||||||||||||||||||||||||||||||
| 276 | 102 | my $startday = _DayOfWeek($monthnum, 1, $self->{'pyear'}); | |||||||||||||||||||||||||||||||||||||||||
| 277 | # add in, if needed, the selected weekdays | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 102 | foreach my $daynum (@{ $self->{'ranges'}{'weekdays'} }) { | |||||||||||||||||||||||||||||||||||||||||
| 279 | 27 | my $offset = $daynum - $startday; # 0 - 6 = -6; start on Saturday, want a Sunday | |||||||||||||||||||||||||||||||||||||||||
| 280 | 27 | for my $week (1, 8, 15, 22, 29, 36) { | |||||||||||||||||||||||||||||||||||||||||
| 281 | 162 | my $monthday = $week + $offset; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 162 | ▶ | next if $monthday < 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 150 | ▶ | next if $monthday > $maxday; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 118 | $days{$monthday} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 102 | @{ $self->{'f'} } = sort { $a <=> $b } keys %days; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 102 | return scalar @{ $self->{'f'} }; | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # routines to increment the counter | ||||||||||||||||||||||||||||||||||||||||||
| 293 | sub inc_h { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 76 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_h: called CC=4 SCAR=14.0
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 295 | 76 | $self->{'pd'}++; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 76 | ▶ | if ($self->{'pd'} == 0 || $self->{'pd'} > $#{$self->{'h'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"pd"} == 0 or $self->{"pd"} > $#{$$self{"h"};}
MC/DC100%2/2
$self->{"pd"} == 0 or $self->{"pd"} > $#{$$self{"h"};}
$self->{"pd"} == 0
$self->{"pd"} > $#{$$self{"h"};}
Truth table100%3/3
A or B
A= $self->{"pd"} == 0B= $self->{"pd"} > $#{$$self{"h"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 297 | 58 | $self->{'pd'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 58 | $self->inc_g(); | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | sub inc_g { | ||||||||||||||||||||||||||||||||||||||||||
| 303 | 58 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_g: called CC=4 SCAR=14.2
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | 58 | $self->{'pc'}++; | |||||||||||||||||||||||||||||||||||||||||
| 305 | 58 | ▶ | if ($self->{'pc'} == 0 || $self->{'pc'} > $#{$self->{'g'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"pc"} == 0 or $self->{"pc"} > $#{$$self{"g"};}
MC/DC50%1/2
$self->{"pc"} == 0 or $self->{"pc"} > $#{$$self{"g"};}
$self->{"pc"} == 0
$self->{"pc"} > $#{$$self{"g"};}
Truth table66%2/3
A or B
A= $self->{"pc"} == 0B= $self->{"pc"} > $#{$$self{"g"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 46 | $self->{'pc'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 46 | $self->inc_f(); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | sub inc_f { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 52 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_f: called CC=4 SCAR=14.0
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 52 | $self->{'pb'}++; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 52 | ▶ | if ($self->{'pb'} == 0 || $self->{'pb'} > $#{$self->{'f'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"pb"} == 0 or $self->{"pb"} > $#{$$self{"f"};}
MC/DC100%2/2
$self->{"pb"} == 0 or $self->{"pb"} > $#{$$self{"f"};}
$self->{"pb"} == 0
$self->{"pb"} > $#{$$self{"f"};}
Truth table100%3/3
A or B
A= $self->{"pb"} == 0B= $self->{"pb"} > $#{$$self{"f"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | 24 | $self->{'pb'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 316 | 24 | $self->inc_e(); | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | # increments currents month, skips to the next year | ||||||||||||||||||||||||||||||||||||||||||
| 321 | # when no months left during the current year | ||||||||||||||||||||||||||||||||||||||||||
| 322 | # | ||||||||||||||||||||||||||||||||||||||||||
| 323 | # if there're no possible months during 5 years in a row, bails out: | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # https://rt.cpan.org/Public/Bug/Display.html?id=109246 | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # | ||||||||||||||||||||||||||||||||||||||||||
| 326 | sub inc_e { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 37 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inc_e: called CC=6 SCAR=18.3
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 37 | $self->{'pa'}++; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 37 | ▶ | if ($self->{'pa'} == 0 || $self->{'pa'} > $#{$self->{'e'}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"pa"} == 0 or $self->{"pa"} > $#{$$self{"e"};}
MC/DC100%2/2
$self->{"pa"} == 0 or $self->{"pa"} > $#{$$self{"e"};}
$self->{"pa"} == 0
$self->{"pa"} > $#{$$self{"e"};}
Truth table100%3/3
A or B
A= $self->{"pa"} == 0B= $self->{"pa"} > $#{$$self{"e"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 15 | $self->{'pa'} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 15 | $self->{'pyear'}++; | |||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | # https://rt.cpan.org/Public/Bug/Display.html?id=109246 | ||||||||||||||||||||||||||||||||||||||||||
| 334 | 15 | push (@{$self->{'set_e_checked_years'}}, $self->{'pyear'}); | |||||||||||||||||||||||||||||||||||||||||
| 335 | 15 | ▶ | if (scalar(@{$self->{'set_e_checked_years'}} > 5)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | confess("Cron line [" . $self->{'initline'} . "] does not define any valid point in time, checked years: [" . | ||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | join(",", @{$self->{'set_e_checked_years'}}) . | |||||||||||||||||||||||||||||||||||||||||
| 338 | "] (ex, 31th of February) "); | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 37 | my $rv = $self->set_f(); | |||||||||||||||||||||||||||||||||||||||||
| 342 | 37 | ▶ | unless ($rv) { ### | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 11 | $self->inc_e; | |||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 37 | $self->{'set_e_checked_years'} = []; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | # and to decrement it | ||||||||||||||||||||||||||||||||||||||||||
| 351 | sub dec_h { | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 42 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dec_h: called CC=3 SCAR=11.2
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 42 | $self->{'pd'}--; | |||||||||||||||||||||||||||||||||||||||||
| 354 | 42 | ▶ | if ($self->{'pd'} == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 38 | $self->{'pd'} = $#{$self->{'h'}}; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 38 | $self->dec_g(); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | sub dec_g { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 38 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dec_g: called CC=3 SCAR=11.2
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 38 | $self->{'pc'}--; | |||||||||||||||||||||||||||||||||||||||||
| 363 | 38 | ▶ | if ($self->{'pc'} == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 30 | $self->{'pc'} = $#{$self->{'g'}}; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 30 | $self->dec_f(); | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | sub dec_f { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 30 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dec_f: called CC=3 SCAR=11.2
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 30 | $self->{'pb'}--; | |||||||||||||||||||||||||||||||||||||||||
| 372 | 30 | ▶ | if ($self->{'pb'} == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | 19 | $self->{'pb'} = $#{$self->{'f'}}; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 19 | $self->dec_e(); | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | sub dec_e { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 31 | ▶ | my $self = shift || confess "Must be called as a method"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dec_e: called CC=4 SCAR=13.9
Pod
undocumented
Condition33%1/3
shift() || confess('Must be called as a method')
MC/DC0%0/2
shift() || confess('Must be called as a method')
shift()
confess('Must be called as a method')
Truth table33%1/3
A || B
A= shift()B= confess('Must be called as a method')
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 31 | $self->{'pa'}--; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 31 | ▶ | if ($self->{'pa'} == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 16 | $self->{'pa'} = $#{$self->{'e'}}; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 16 | $self->{'pyear'}--; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 31 | my $rv = $self->set_f(); | |||||||||||||||||||||||||||||||||||||||||
| 386 | 31 | ▶ | unless ($rv) { ### | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 12 | $self->dec_e; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 31 | $self->{'pb'} = $#{$self->{'f'}}; | |||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | # These two routines courtesy of B Paulsen | ||||||||||||||||||||||||||||||||||||||||||
| 393 | sub _isLeapYear { | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 204 | ▶ | my $year = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_isLeapYear: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 204 | ▶ | return !($year % 400) || ( !( $year % 4 ) && ( $year % 100 ) ) ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $year % 400 or not $year % 4 and $year % 100
not $year % 4 and $year % 100
MC/DC66%2/3
not $year % 400 or not $year % 4 and $year % 100
not $year % 400
not $year % 4
$year % 100
Truth table75%3/4
not(A) or not(B) and C
A= not $year % 400B= not $year % 4C= $year % 100
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | sub _DayOfWeek { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 102 | ▶ | my ( $month, $day, $year ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_DayOfWeek: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 102 | my $flag = _isLeapYear( $year ); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 102 | ▶ | my @months = ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | $flag ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||
| 404 | $flag ? 3 : 4, | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 4, 0, 2, 5, 0, 3, 6, 1, 4, 6 ); | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 102 | my @century = ( 4, 2, 0, 6 ); | |||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 102 | my $dow = $year % 100; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 102 | $dow += int( $dow / 4 ); | |||||||||||||||||||||||||||||||||||||||||
| 410 | 102 | $dow += $day + $months[$month-1]; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 102 | $dow += $century[ ( int($year/100) - 1 ) % 4 ]; | |||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | 102 | return ($dow-1) % 7; | |||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | ▶ | sub TRACE {} | |||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TRACE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | __END__ | ||||||||||||||||||||||||||||||||||||||||||