| 1 | package Cron::Toolkit::Pattern; | ||||||||||||||||||||||||||||||||||||||||||
| 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 Cron::Toolkit::Utils qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 777 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 777 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 8 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||
| 9 | children => [], | ||||||||||||||||||||||||||||||||||||||||||
| 10 | field_type => $args{field_type} | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 777 | }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 777 | ▶ | $self->{value} = $args{value} if defined $args{value}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 777 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 91 | ▶ | sub add_child { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_child: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 91 | my ($self, $child) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 91 | push @{$self->{children}}, $child; | |||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 140 | ▶ | sub children { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 140 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 140 | return $self->{children}; | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 127 | ▶ | sub has_children { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_children: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 127 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 127 | ▶ | return scalar @{ $self->{children} } ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->{type} = $value if defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | return $self->{type}; # Return the value (either set or current) | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2083474 | ▶ | sub field_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
field_type: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2083474 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 2083474 | ▶ | $self->{field_type} = $value if defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 2083474 | return $self->{field_type}; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 1952065 | ▶ | sub value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
value: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1952065 | my ($self, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 1952065 | ▶ | $self->{value} = $value if defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1952065 | return $self->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 479 | ▶ | sub lowest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
lowest: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 479 | my ( $self, $tm ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 479 | my ( $min, $max ) = @{ $LIMITS{ $self->field_type } }; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 479 | ▶ | $max = $tm->length_of_month if $self->field_type eq 'dom'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 479 | for my $v ( $min .. $max ) { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 1551 | my $test_tm = $tm; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 1551 | ▶ | $test_tm = $test_tm->with_day_of_month($v) if $self->field_type eq 'dom'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 1551 | ▶ | return $v if $self->match($v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 479 | ▶ | sub highest { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
highest: called CC=5 SCAR=16.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 479 | my ( $self, $tm ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 479 | my ( $min, $max ) = @{ $LIMITS{ $self->field_type } }; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 479 | ▶ | $max = $tm->length_of_month if $self->field_type eq 'dom'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 479 | for my $v ( reverse $min .. $max ) { | |||||||||||||||||||||||||||||||||||||||||
| 69 | 20943 | my $test_tm = $tm; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 20943 | ▶ | $test_tm = $test_tm->with_day_of_month($v) if $self->field_type eq 'dom'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 20943 | ▶ | return $v if $self->match($v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 94 | ▶ | sub english_unit { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
english_unit: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 94 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 94 | ▶ | my $unit = $self->field_type =~ /^(dow|dom)$/ ? 'day' : $self->field_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 94 | ▶ | $unit .= 's' if ($self->type eq 'single' && $self->value != 1 && $self->field_type ne 'year'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$self->type eq "single" and $self->value != 1 and $self->field_type ne "year"
$self->type eq "single" and $self->value != 1
MC/DC0%0/3
$self->type eq "single" and $self->value != 1 and $self->field_type ne "year"
$self->type eq "single"
$self->value != 1
$self->field_type ne "year"
Truth table25%1/4
A and B and C
A= $self->type eq "single"B= $self->value != 1C= $self->field_type ne "year"
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 94 | return $unit; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 136 | ▶ | sub english_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
english_value: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 136 | my ( $self ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 136 | my $value = $self->{value}; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 136 | ▶ | die "missing value" unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 136 | ▶ | return 'the ' . num_to_ordinal($value) if $self->field_type eq 'dom'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 108 | ▶ | return $MONTH_NAMES{$value} if $self->field_type eq 'month'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 79 | ▶ | return $DAY_NAMES{$value} if $self->field_type eq 'dow'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 55 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 664 | ▶ | sub _dump_tree { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dump_tree: called CC=17 SCAR=28.4
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 664 | my ($self, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 664 | ▶ | $indent //= ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$indent //= ""
MC/DC0%0/1
$indent //= ""
$indent
Truth table50%1/2
A
A= $indent
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 664 | my $type = $self->type; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | # Simple leaf values — inline | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 664 | ▶ | if ($type eq 'wildcard') { return '*'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 494 | ▶ | if ($type eq 'unspecified') { return '?'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 410 | ▶ | if ($type eq 'single') { return $self->{value}; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 62 | ▶ | if ($type eq 'last') { return $self->{value} // 'L'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"value"} // "L"
MC/DC0%0/1
$self->{"value"} // "L"
$self->{"value"}
Truth table50%1/2
A
A= $self->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 52 | ▶ | if ($type eq 'lastW') { return 'LW'; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 51 | ▶ | if ($type eq 'nearest_weekday') { return $self->{value}; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 48 | ▶ | if ($type eq 'nth') { return $self->{value}; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 39 | my @children = @{$self->{children}}; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 39 | ▶ | return '' unless @children; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 39 | my $out = ""; | |||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 39 | ▶ | if ($type eq 'range') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 19 | return $children[0]->_dump_tree($indent) . '-' . $children[1]->_dump_tree($indent); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 20 | ▶ | if ($type eq 'step') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 11 | my $base = $children[0]->_dump_tree($indent . ' '); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 11 | $out .= $base . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | $out .= "${indent}└─ /$children[1]{value}"; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 11 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | ▶ | if ($type eq 'list') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | $out = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | for my $i (0 .. $#children) { | |||||||||||||||||||||||||||||||||||||||||
| 127 | 27 | ▶ | my $prefix = ($i == $#children) ? '└─ ' : '├─ '; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 27 | ▶ | my $next_indent = $indent . ($i == $#children ? ' ' : '│ '); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 27 | $out .= "${indent}$prefix" . $children[$i]->_dump_tree($next_indent) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | chomp $out; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | return $type; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||