| 1 | package Cron::Toolkit::Pattern::Last; | ||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 2 | ▶ | use parent 'Cron::Toolkit::Pattern'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 2 | ▶ | use Cron::Toolkit::Utils qw(:all); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 55718 | ▶ | sub type { return 'last'; } | ||||||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 16 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||
| 10 | 16 | my ($class, %args) = @_; | |||||||||||||
| 11 | 16 | my $self = $class->SUPER::new(%args); | |||||||||||||
| 12 | |||||||||||||||
| 13 | 16 | ▶ | if ($args{field_type} eq 'dow') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 14 | # DOW: dayL or L (L = 7L) | ||||||||||||||
| 15 | 10 | ▶ | if ($args{value} =~ /^(\d+)L$/i) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 16 | 9 | $self->{dow} = $1; | |||||||||||||
| 17 | } else { | ||||||||||||||
| 18 | 1 | $self->{dow} = 7; # L alone = last Saturday | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | } elsif ($args{field_type} eq 'dom') { | ||||||||||||||
| 21 | # DOM: L or L-offset | ||||||||||||||
| 22 | 6 | ▶ | if ($args{value} =~ /^L-?(\d*)$/i) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 6 | ▶ | $self->{offset} = $1 eq '' ? 0 : $1; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | } | ||||||||||||||
| 25 | } | ||||||||||||||
| 26 | |||||||||||||||
| 27 | 16 | return $self; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 55621 | ▶ | sub match { | ||||||||||||
|
Subroutine
match: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||
| 31 | 55621 | my ($self, $value, $tm) = @_; | |||||||||||||
| 32 | |||||||||||||||
| 33 | 55621 | ▶ | if ($self->field_type eq 'dom') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 34 | 55494 | ▶ | my $target = $tm->length_of_month - ($self->{offset} // 0); | ||||||||||||
|
Condition50%1/2
$self->{"offset"} // 0
MC/DC0%0/1
$self->{"offset"} // 0
$self->{"offset"}
Truth table50%1/2
A
A= $self->{"offset"}
| |||||||||||||||
| 35 | 55494 | return $tm->day_of_month == $target; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 127 | ▶ | if ($self->field_type eq 'dow') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 39 | 127 | my $target_dow = $self->{dow}; | |||||||||||||
| 40 | |||||||||||||||
| 41 | # Find the last occurrence of target_dow in this month | ||||||||||||||
| 42 | 127 | my $last_day = $tm->length_of_month; | |||||||||||||
| 43 | 127 | my $last_tm = $tm->with_day_of_month($last_day); | |||||||||||||
| 44 | 127 | my $days_back = ($last_tm->day_of_week - $target_dow + 7) % 7; | |||||||||||||
| 45 | 127 | my $last_occurrence = $last_day - $days_back; | |||||||||||||
| 46 | |||||||||||||||
| 47 | 127 | return $tm->day_of_month == $last_occurrence; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | |||||||||||||||
| 50 | 0 | return 0; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | |||||||||||||||
| 53 | 10 | ▶ | sub to_english { | ||||||||||||
|
Subroutine
to_english: called CC=5 SCAR=16.4
Pod
undocumented
| |||||||||||||||
| 54 | 10 | my ($self) = @_; | |||||||||||||
| 55 | |||||||||||||||
| 56 | 10 | ▶ | if ($self->field_type eq 'dom') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 6 | ▶ | if ($self->{offset} == 0) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | 5 | return "on the last day"; | |||||||||||||
| 59 | } else { | ||||||||||||||
| 60 | 1 | return "on the " . num_to_ordinal($self->{offset}) . " to last day"; | |||||||||||||
| 61 | } | ||||||||||||||
| 62 | } | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 4 | ▶ | if ($self->field_type eq 'dow') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 4 | ▶ | my $day_name = $DAY_NAMES{$self->{dow}} // 'day'; | ||||||||||||
|
Condition50%1/2
$Cron::Toolkit::Pattern::Last::DAY_NAMES{$self->{"dow"}} // "day"
MC/DC0%0/1
$Cron::Toolkit::Pattern::Last::DAY_NAMES{$self->{"dow"}} // "day"
$Cron::Toolkit::Pattern::Last::DAY_NAMES{$self->{"dow"}}
Truth table50%1/2
A
A= $Cron::Toolkit::Pattern::Last::DAY_NAMES{$self->{"dow"}}
| |||||||||||||||
| 66 | 4 | return "on the last $day_name"; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | |||||||||||||||
| 69 | 0 | return "last"; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 2 | 1; | |||||||||||||