File Coverage

blib/lib/Date/Holidays/Adapter/CZ.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 4 0.0
condition n/a
subroutine 4 7 57.1
pod 2 2 100.0
total 18 46 39.1


line stmt bran cond sub pod time code
1             package Date::Holidays::Adapter::CZ;
2              
3 1     1   299227 use strict;
  1         3  
  1         45  
4 1     1   5 use warnings;
  1         3  
  1         90  
5              
6 1     1   6 use base 'Date::Holidays::Adapter';
  1         2  
  1         3687  
7              
8 1     1   14 use vars qw($VERSION);
  1         3  
  1         623  
9              
10             $VERSION = '1.35';
11              
12             my $format = '%#:%m%d';
13              
14             # Lifted from Date::Holidays::CZ example: svatky.plx
15             # Ref: https://metacpan.org/source/SMITHFARM/Date-Holidays-CZ-0.13/example/svatky.plx
16             my %holiday_names = (
17             'obss' => 'Restoration Day of the Independent Czech State',
18             'veln' => 'Easter Sunday',
19             'velp' => 'Easter Monday',
20             'svpr' => 'Labor Day',
21             'dvit' => 'Liberation Day',
22             'cyme' => 'Saints Cyril and Methodius Day',
23             'mhus' => 'Jan Hus Day',
24             'wenc' => 'Feast of St. Wenceslas (Czech Statehood Day)',
25             'vzcs' => 'Independent Czechoslovak State Day',
26             'bojs' => 'Struggle for Freedom and Democracy Day',
27             'sted' => 'Christmas Eve',
28             'van1' => 'Christmas Day',
29             'van2' => 'Feast of St. Stephen',
30             );
31              
32             sub holidays {
33 0     0 1   my ($self, %params) = @_;
34              
35 0           my $sub = $self->{_adaptee}->can('holidays');
36              
37 0 0         if ($sub) {
38 0           return &{$sub}(YEAR => $params{'year'});
  0            
39             } else {
40 0           return {};
41             }
42             }
43              
44             sub is_holiday {
45 0     0 1   my ($self, %params) = @_;
46              
47             my $holidays = Date::Holidays::CZ::holidays(
48 0           YEAR => $params{'year'},
49             FORMAT => $format,
50             );
51              
52 0           my $holidays_hashref = $self->_transform_arrayref_to_hashref($holidays);
53              
54 0           my $holiday_date = sprintf('%02s%02s', $params{month}, $params{day});
55              
56 0           my $holiday = $holidays_hashref->{$holiday_date};
57              
58 0 0         if ($holiday) {
59 0           return $holiday;
60             } else {
61 0           return '';
62             }
63             }
64              
65             sub _transform_arrayref_to_hashref {
66 0     0     my ($self, $arrayref_of_holidays) = @_;
67              
68 0           my $hashref_of_holidays;
69              
70 0           foreach my $entry (@{$arrayref_of_holidays}) {
  0            
71 0           my ($shortname, $key) = split /:/, $entry;
72 0           $hashref_of_holidays->{$key} = $holiday_names{$shortname};
73             }
74              
75 0           return $hashref_of_holidays;
76             }
77              
78             1;
79              
80             __END__
81              
82             =pod
83              
84             =encoding UTF-8
85              
86             =head1 NAME
87              
88             Date::Holidays::Adapter::CZ - an adapter class for Date::Holidays::CZ
89              
90             =head1 VERSION
91              
92             This POD describes version 1.35 of Date::Holidays::Adapter::CZ
93              
94             =head1 DESCRIPTION
95              
96             The is the adapter class for L<Date::Holidays::CZ>.
97              
98             =head1 SUBROUTINES/METHODS
99              
100             =head2 new
101              
102             The constructor, takes a single named argument, B<countrycode>
103              
104             The constructor is inherited from L<Date::Holidays::Adapter>
105              
106             =head2 is_holiday
107              
108             The C<is_holiday> method, takes 3 named arguments, C<year>, C<month> and C<day>
109              
110             Returns an indication of whether the day is a holiday in the calendar of the
111             country referenced by C<countrycode> in the call to the constructor C<new>.
112              
113             =head2 holidays
114              
115             The B<holidays> method, takes a single named argument, B<year>
116              
117             returns a reference to a hash holding the calendar of the country referenced by
118             B<countrycode> in the call to the constructor B<new>.
119              
120             The calendar will spand for a year and the keys consist of B<month> and B<day>
121             concatenated.
122              
123             =head1 DIAGNOSTICS
124              
125             Please refer to DIAGNOSTICS in L<Date::Holidays>
126              
127             =head1 DEPENDENCIES
128              
129             =over
130              
131             =item * L<Date::Japanese::Holiday>
132              
133             =item * L<Date::Holidays::Adapter>
134              
135             =back
136              
137             =head1 INCOMPATIBILITIES
138              
139             Please refer to INCOMPATIBILITIES in L<Date::Holidays>
140              
141             =head1 BUGS AND LIMITATIONS
142              
143             B<is_holiday> or similar method is not implemented in L<Date::Holidays::CZ> as
144             of version 0.13.
145              
146             The adapter does currently not support the complex API of
147             L<Date::Holidays::CZ> B<holidays>.
148              
149             Please refer to BUGS AND LIMITATIONS in L<Date::Holidays>
150              
151             =head1 BUG REPORTING
152              
153             Please refer to BUG REPORTING in L<Date::Holidays>
154              
155             =head1 AUTHOR
156              
157             Jonas Brømsø, (jonasbn) - C<< <jonasbn@cpan.org> >>
158              
159             =head1 LICENSE AND COPYRIGHT
160              
161             L<Date::Holidays> and related modules are (C) by Jonas Brømsø, (jonasbn)
162             2004-2024
163              
164             Date-Holidays and related modules are released under the Artistic License 2.0
165              
166             =cut