| 1 | package Cron::Toolkit::Pattern::Nth; | ||||||||||
| 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 | 10 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 8 | 10 | my ($class, %args) = @_; | |||||||||
| 9 | 10 | my $self = $class->SUPER::new(%args); | |||||||||
| 10 | 10 | $self->{dow} = $args{dow}; | |||||||||
| 11 | 10 | $self->{nth} = $args{nth}; | |||||||||
| 12 | 10 | return $self; | |||||||||
| 13 | } | ||||||||||
| 14 | |||||||||||
| 15 | 434 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 16 | 434 | return 'nth'; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 365 | ▶ | sub match { | ||||||||
|
Subroutine
match: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 20 | 365 | my ($self, $value, $tm) = @_; | |||||||||
| 21 | 365 | my $target_dow = $self->{dow}; | |||||||||
| 22 | 365 | my $nth = $self->{nth}; | |||||||||
| 23 | 365 | my $dom = $tm->day_of_month; | |||||||||
| 24 | |||||||||||
| 25 | 365 | my $count = 0; | |||||||||
| 26 | 365 | for my $d (1 .. $dom - 1) { | |||||||||
| 27 | 5550 | ▶ | $count++ if $tm->with_day_of_month($d)->day_of_week == $target_dow; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | 365 | ▶ | return 0 unless $tm->day_of_week == $target_dow; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 59 | return $count + 1 == $nth; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 9 | ▶ | sub to_english { | ||||||||
|
Subroutine
to_english: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 35 | 9 | my ($self) = @_; | |||||||||
| 36 | 9 | my $day = $DAY_NAMES{ $self->{dow} }; | |||||||||
| 37 | 9 | my $nth = num_to_ordinal( $self->{nth} ); | |||||||||
| 38 | 9 | return "on the $nth $day"; | |||||||||
| 39 | } | ||||||||||
| 40 | |||||||||||
| 41 | 2 | 1; | |||||||||