line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Cron::Holiday; |
2
|
1
|
|
|
1
|
|
19897
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
109
|
use Carp 'croak'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
321
|
use Mojar::Cron::Datetime; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
272
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Attributes |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has holidays => sub { {} }; |
10
|
|
|
|
|
|
|
has 'linked'; |
11
|
|
|
|
|
|
|
has 'error'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Methods |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub holiday { |
16
|
52
|
|
|
52
|
1
|
16765
|
my ($self, $date) = (shift, shift); |
17
|
52
|
|
66
|
|
|
96
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
18
|
52
|
|
|
|
|
93
|
my $holidays = $self->holidays; |
19
|
52
|
|
|
|
|
179
|
my $linked = $self->linked; |
20
|
|
|
|
|
|
|
|
21
|
52
|
100
|
|
|
|
147
|
if (ref $date eq 'ARRAY') { |
22
|
|
|
|
|
|
|
# Recurse over a setter bundle |
23
|
2
|
50
|
|
|
|
9
|
return [map $self->holiday($_ => $_[0]), @$date] if @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Recurse over a getter bundle |
26
|
0
|
|
|
|
|
0
|
return [map $self->holiday($_), @$date]; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Scalar |
30
|
50
|
50
|
|
|
|
170
|
croak 'Bad format' unless $date =~ /^\d\d\d\d-\d\d-\d\d$/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Setter |
33
|
50
|
100
|
|
|
|
118
|
$holidays->{$date} = !! $_[0], return $self if @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Getter |
36
|
34
|
100
|
|
|
|
92
|
return $holidays->{$date} if exists $holidays->{$date}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Defer if possible |
39
|
11
|
100
|
|
|
|
14
|
return $linked->holiday($date) if $linked; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Negative |
42
|
10
|
|
|
|
|
26
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub next_holiday { |
46
|
7
|
|
|
7
|
1
|
853
|
my ($self, $date) = @_; |
47
|
7
|
|
33
|
|
|
15
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
48
|
7
|
|
|
|
|
15
|
my $holidays = $self->holidays; |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
54
|
my @dates = sort grep $holidays->{$_}, keys %$holidays; |
51
|
7
|
|
100
|
|
|
53
|
shift @dates while @dates and $dates[0] lt $date; |
52
|
7
|
100
|
|
|
|
27
|
@dates ? $dates[0] : undef; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
0
|
0
|
|
sub load { croak q{Method 'load' not implemented by subclass} } |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
1; |
58
|
|
|
|
|
|
|
__END__ |