line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Cron::Holiday; |
2
|
1
|
|
|
1
|
|
242077
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
10
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
246
|
use Carp 'croak'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
5
|
1
|
|
|
1
|
|
390
|
use Mojar::Cron::Datetime; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
396
|
|
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
|
21911
|
my ($self, $date) = (shift, shift); |
17
|
52
|
|
66
|
|
|
116
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
18
|
52
|
|
|
|
|
129
|
my $holidays = $self->holidays; |
19
|
52
|
|
|
|
|
229
|
my $linked = $self->linked; |
20
|
|
|
|
|
|
|
|
21
|
52
|
100
|
|
|
|
198
|
if (ref $date eq 'ARRAY') { |
22
|
|
|
|
|
|
|
# Recurse over a setter bundle |
23
|
2
|
50
|
|
|
|
13
|
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
|
|
|
|
225
|
croak 'Bad format' unless $date =~ /^\d\d\d\d-\d\d-\d\d$/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Setter |
33
|
50
|
100
|
|
|
|
144
|
$holidays->{$date} = !! $_[0], return $self if @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Getter |
36
|
34
|
100
|
|
|
|
125
|
return $holidays->{$date} if exists $holidays->{$date}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Defer if possible |
39
|
11
|
100
|
|
|
|
19
|
return $linked->holiday($date) if $linked; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Negative |
42
|
10
|
|
|
|
|
35
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub next_holiday { |
46
|
7
|
|
|
7
|
1
|
2518
|
my ($self, $date) = @_; |
47
|
7
|
|
33
|
|
|
19
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
48
|
7
|
|
|
|
|
22
|
my $holidays = $self->holidays; |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
115
|
my @dates = sort grep $holidays->{$_}, keys %$holidays; |
51
|
7
|
|
100
|
|
|
56
|
shift @dates while @dates and $dates[0] lt $date; |
52
|
7
|
100
|
|
|
|
41
|
@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__ |