line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojar::Cron::Holiday; |
2
|
1
|
|
|
1
|
|
23066
|
use Mojo::Base -base; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
177
|
use Carp 'croak'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
55
|
|
5
|
1
|
|
|
1
|
|
300
|
use Mojar::Cron::Datetime; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
360
|
|
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
|
18647
|
my ($self, $date) = (shift, shift); |
17
|
52
|
|
66
|
|
|
142
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
18
|
52
|
|
|
|
|
135
|
my $holidays = $self->holidays; |
19
|
52
|
|
|
|
|
257
|
my $linked = $self->linked; |
20
|
|
|
|
|
|
|
|
21
|
52
|
100
|
|
|
|
225
|
if (ref $date eq 'ARRAY') { |
22
|
|
|
|
|
|
|
# Recurse over a setter bundle |
23
|
2
|
50
|
|
|
|
15
|
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
|
|
|
|
189
|
croak 'Bad format' unless $date =~ /^\d\d\d\d-\d\d-\d\d$/; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# Setter |
33
|
50
|
100
|
|
|
|
167
|
$holidays->{$date} = !! $_[0], return $self if @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Getter |
36
|
34
|
100
|
|
|
|
123
|
return $holidays->{$date} if exists $holidays->{$date}; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Defer if possible |
39
|
11
|
100
|
|
|
|
27
|
return $linked->holiday($date) if $linked; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Negative |
42
|
10
|
|
|
|
|
36
|
return undef; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub next_holiday { |
46
|
7
|
|
|
7
|
1
|
1722
|
my ($self, $date) = @_; |
47
|
7
|
|
33
|
|
|
21
|
$date //= substr(Mojar::Cron::Datetime->now->to_string, 0, 10); |
48
|
7
|
|
|
|
|
22
|
my $holidays = $self->holidays; |
49
|
|
|
|
|
|
|
|
50
|
7
|
|
|
|
|
72
|
my @dates = sort grep $holidays->{$_}, keys %$holidays; |
51
|
7
|
|
100
|
|
|
64
|
shift @dates while @dates and $dates[0] lt $date; |
52
|
7
|
100
|
|
|
|
44
|
@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__ |