Toolkit/Pattern/Last.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 80.0% 16 / 20 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 82.9% 68 / 82 CC 13 SCAR 14.3
CC
13
Cov
88%
new
6.0
to_english
5.1
match
4.1
CRAP 4.2
« Toolkit/Utils.pm ↑ Summary Toolkit/Pattern/LastW.pm »
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
BranchTrueFalseTotal
if ($args{'field_type'} eq 'dow') { } 10 6 16
elsif ($args{'field_type'} eq 'dom') { } 6 0 6
14 # DOW: dayL or L (L = 7L)
15 10 ▶ if ($args{value} =~ /^(\d+)L$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'value'} =~ /^(\d+)L$/i) { } 9 1 10
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
BranchTrueFalseTotal
if ($args{"value"} =~ /^L-?(\d*)$/i) 6 0 6
23 6 ▶ $self->{offset} = $1 eq '' ? 0 : $1;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '' ? : 5 1 6
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
BranchTrueFalseTotal
if ($self->field_type eq "dom") 55494 127 55621
34 55494 ▶ my $target = $tm->length_of_month - ($self->{offset} // 0);
Condition50%1/2
$self->{"offset"} // 0
l!l
554940
MC/DC0%0/1
$self->{"offset"} // 0
$self->{"offset"}
Truth table50%1/2
A
A= $self->{"offset"}
Aresult
11
00
35 55494 return $tm->day_of_month == $target;
36 }
37  
38 127 ▶ if ($self->field_type eq 'dow') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->field_type eq "dow") 127 0 127
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
BranchTrueFalseTotal
if ($self->field_type eq "dom") 6 4 10
57 6 ▶ if ($self->{offset} == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'offset'} == 0) { } 5 1 6
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
BranchTrueFalseTotal
if ($self->field_type eq "dow") 4 0 4
65 4 ▶ my $day_name = $DAY_NAMES{$self->{dow}} // 'day';
Condition50%1/2
$Cron::Toolkit::Pattern::Last::DAY_NAMES{$self->{"dow"}} // "day"
l!l
40
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"}}
Aresult
11
00
66 4 return "on the last $day_name";
67 }
68  
69 0 return "last";
70 }
71  
72 2 1;
« Toolkit/Utils.pm ↑ Summary Toolkit/Pattern/LastW.pm »