Toolkit/Pattern/NearestWeekday.pm

filter: Statementstmt 100% 39 / 39 Branchbran 100% 10 / 10 Conditioncond 80.9% 17 / 21 MC/DCmcdc 63.6% 7 / 11 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 4 totaltotal 87.1% 81 / 93 CC 13 SCAR 21.8
CC
13
Cov
94%
match
13.1
BEGIN
1.0
BEGIN
1.0
CRAP 8.9
« Toolkit.pm ↑ Summary Toolkit/Pattern.pm »
1 package Cron::Toolkit::Pattern::NearestWeekday;
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(num_to_ordinal);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
8 3 my ($class, %args) = @_;
9 3 my $self = $class->SUPER::new(%args);
10 3 $self->{dom} = $args{dom};
11 3 return $self;
12 }
13  
14 213 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod undocumented
15 213 return 'nearest_weekday';
16 }
17  
18 186 ▶sub match {
Subroutine match: called CC=13 SCAR=25.7
Pod undocumented
19 186 my ( $self, undef, $tm ) = @_;
20 186 my $day = $self->{dom};
21 186 my $dom = $tm->day_of_month;
22 186 my $dow = $tm->day_of_week;
23 186 my $days_in_month = $tm->length_of_month;
24 186 ▶ return 0 if $day < 1 || $day > $days_in_month;
Branch: 1 branch
BranchTrueFalseTotal
if $day < 1 or $day > $days_in_month 30 156 186
Condition66%2/3
$day < 1 or $day > $days_in_month
l!l&&r!l&&!r
030156
MC/DC50%1/2
$day < 1 or $day > $days_in_month
$day < 1 $day > $days_in_month
Truth table66%2/3
A or B
A= $day < 1B= $day > $days_in_month
ABresult
1X1
011
000
25 156 my $target_tm = $tm->with_day_of_month($day);
26 156 my $target_dow = $target_tm->day_of_week;
27  
28 156 ▶ if ( $target_dow >= 2 && $target_dow <= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target_dow >= 2 and $target_dow <= 5) 79 77 156
Condition100%3/3
$target_dow >= 2 and $target_dow <= 5
!ll&&!rl&&r
27579
MC/DC100%2/2
$target_dow >= 2 and $target_dow <= 5
$target_dow >= 2 $target_dow <= 5
Truth table100%3/3
A and B
A= $target_dow >= 2B= $target_dow <= 5
ABresult
0X0
100
111
29 79 ▶ return $dom == $day ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dom == $day ? : 4 75 79
30 }
31 77 my $before = $target_tm->minus_days(1);
32 77 my $after = $target_tm->plus_days(1);
33 77 my $before_dow = $before->day_of_week;
34 77 my $after_dow = $after->day_of_week;
35 77 ▶ if ( $before_dow >= 1 && $before_dow <= 5 && $dom == $day - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($before_dow >= 1 and $before_dow <= 5 and $dom == $day - 1) 1 76 77
Condition83%5/6
$before_dow >= 1 and $before_dow <= 5 and $dom == $day - 1
!ll&&!rl&&r
33431
$before_dow >= 1 and $before_dow <= 5
!ll&&!rl&&r
03344
MC/DC66%2/3
$before_dow >= 1 and $before_dow <= 5 and $dom == $day - 1
$before_dow >= 1 $before_dow <= 5 $dom == $day - 1
Truth table75%3/4
A and B and C
A= $before_dow >= 1B= $before_dow <= 5C= $dom == $day - 1
ABCresult
0XX0
10X0
1100
1111
36 1 return 1;
37 }
38 76 ▶ if ( $after_dow >= 1 && $after_dow <= 5 && $dom == $day + 1 && $day + 1 <= $days_in_month ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($after_dow >= 1 and $after_dow <= 5 and $dom == $day + 1 and $day + 1 <= $days_in_month) 1 75 76
Condition77%7/9
$after_dow >= 1 and $after_dow <= 5 and $dom == $day + 1 and $day + 1 <= $days_in_month
!ll&&!rl&&r
7501
$after_dow >= 1 and $after_dow <= 5 and $dom == $day + 1
!ll&&!rl&&r
43321
$after_dow >= 1 and $after_dow <= 5
!ll&&!rl&&r
04333
MC/DC50%2/4
$after_dow >= 1 and $after_dow <= 5 and $dom == $day + 1 and $day + 1 <= $days_in_month
$after_dow >= 1 $after_dow <= 5 $dom == $day + 1 $day + 1 <= $days_in_month
Truth table60%3/5
A and B and C and D
A= $after_dow >= 1B= $after_dow <= 5C= $dom == $day + 1D= $day + 1 <= $days_in_month
ABCDresult
0XXX0
10XX0
110X0
11100
11111
39 1 return 1;
40 }
41 75 return 0;
42 }
43  
44 3 ▶sub to_english {
Subroutine to_english: called CC=1 SCAR=0.0
Pod undocumented
45 3 my $self = shift;
46 3 return "on the nearest weekday to the " . num_to_ordinal($self->{dom});
47 }
48  
49 2 1;
50  
51  
« Toolkit.pm ↑ Summary Toolkit/Pattern.pm »