File Coverage

blib/lib/Date/Holidays/Adapter/ES.pm
Criterion Covered Total %
statement 15 53 28.3
branch 0 14 0.0
condition 0 6 0.0
subroutine 5 7 71.4
pod 2 2 100.0
total 22 82 26.8


line stmt bran cond sub pod time code
1             package Date::Holidays::Adapter::ES;
2              
3 2     2   221511 use strict;
  2         3  
  2         62  
4 2     2   9 use warnings;
  2         4  
  2         125  
5              
6 2     2   14 use base 'Date::Holidays::Adapter';
  2         4  
  2         900  
7 2     2   13 use Module::Load; # load
  2         2  
  2         18  
8              
9 2     2   104 use vars qw($VERSION);
  2         9  
  2         982  
10              
11             $VERSION = '1.35';
12              
13             sub holidays {
14 0     0 1   my ($self, %params) = @_;
15              
16 0           my $dh = $self->{_adaptee}->new();
17              
18 0           my $holidays_es_hashref = {};
19 0           my $holidays_ca_es_hashref = {};
20              
21 0 0         if ($dh) {
22 0           $holidays_es_hashref = $dh->holidays(year => $params{year});
23              
24 0 0 0       if ($params{region} and $params{region} eq 'ca') {
25              
26 0           eval { load 'Date::Holidays::CA_ES'; }; # From Module::Load
  0            
27 0 0         if ($@) {
28 0           warn "Unable to load: Date::Holidays::CA_ES - $@\n";
29 0           return $holidays_es_hashref;
30             }
31              
32 0           my $dh_ca_es = Date::Holidays::CA_ES->new();
33 0           $holidays_ca_es_hashref = $dh_ca_es->holidays(year => $params{year});
34             }
35             } else {
36 0           return;
37             }
38              
39 0           foreach my $key (keys %{$holidays_ca_es_hashref}) {
  0            
40 0           $holidays_es_hashref->{$key} = $holidays_ca_es_hashref->{$key};
41             }
42              
43 0           return $holidays_es_hashref;
44             }
45              
46             sub is_holiday {
47 0     0 1   my ($self, %params) = @_;
48              
49 0           my $dh = $self->{_adaptee}->new();
50              
51 0 0         if ($dh) {
52 0           my $holiday = $dh->is_holiday(year => $params{year}, month => $params{month}, day => $params{day});
53              
54 0 0 0       if ($params{region} and $params{region} eq 'ca') {
55              
56 0           eval { load 'Date::Holidays::CA_ES'; }; # From Module::Load
  0            
57 0 0         if ($@) {
58 0           warn "Unable to load: Date::Holidays::CA_ES - $@\n";
59 0           return $holiday;
60             }
61              
62 0           my $dh_ca_es = Date::Holidays::CA_ES->new();
63              
64 0           my $holidays = $dh_ca_es->holidays(year => $params{year}, region => $params{region});
65              
66 0           my $holiday_date = sprintf('%02s%02s', $params{month}, $params{day});
67              
68 0           $holiday = $holidays->{$holiday_date};
69              
70 0 0         if ($holiday) {
71 0           return $holiday;
72             } else {
73 0           return '';
74             }
75             }
76              
77 0           return $holiday
78             } else {
79 0           return '';
80             }
81             }
82              
83             1;
84              
85             __END__
86              
87             =pod
88              
89             =encoding UTF-8
90              
91             =head1 NAME
92              
93             Date::Holidays::Adapter::ES - adapter class for Date::Holidays::ES and Date::Holidays::CA_ES
94              
95             =head1 VERSION
96              
97             This POD describes version 1.35 of Date::Holidays::Adapter::ES
98              
99             =head1 DESCRIPTION
100              
101             The is the an adapter class. It adapts:
102              
103             =over
104              
105             =item * L<Date::Holidays::ES>
106              
107             =item * L<Date::Holidays::CA_ES>
108              
109             =back
110              
111             The adapter merges the information on holidays from the two distributions mentioned above.
112              
113             The L<Date::Holidays::ES> acts as the primary holiday indication, holidays special for the
114             Catalan region is accessible when the optional C<region> parameter is used. Please see the
115             descriptions for the methods below.
116              
117             =head1 SUBROUTINES/METHODS
118              
119             =head2 new
120              
121             The constructor is inherited from L<Date::Holidays::Adapter>
122              
123             =head2 is_holiday
124              
125             The C<is_holiday> method, takes 3 named arguments, C<year>, C<month> and C<day>
126              
127             Returns an indication of whether the day is a holiday in the calendar of the
128             country referenced by C<countrycode> in the call to the constructor C<new>.
129              
130             It supports the optional parameter C<region> for specifying a region within Spain.
131              
132             =head2 holidays
133              
134             The L<holidays> method, takes a single named argument, C<year>
135              
136             Returns a reference to a hash holding the calendar of the country referenced by
137             C<countrycode> in the call to the constructor L<new>.
138              
139             The calendar will spand for a year and the keys consist of C<month> and C<day>
140             concatenated.
141              
142             It supports the optional parameter C<region> for specifying a region within Spain.
143              
144             =head1 DIAGNOSTICS
145              
146             Please refer to DIAGNOSTICS in L<Date::Holidays>
147              
148             =head1 DEPENDENCIES
149              
150             =over
151              
152             =item * L<Date::Holidays::ES>
153              
154             =item * L<Date::Holidays::CA_ES>
155              
156             =item * L<Date::Holidays::Adapter>
157              
158             =back
159              
160             =head1 INCOMPATIBILITIES
161              
162             Please refer to INCOMPATIBILITIES in L<Date::Holidays>
163              
164             =head1 BUGS AND LIMITATIONS
165              
166             Please refer to BUGS AND LIMITATIONS in L<Date::Holidays>
167              
168             =head1 BUG REPORTING
169              
170             Please refer to BUG REPORTING in L<Date::Holidays>
171              
172             =head1 AUTHOR
173              
174             Jonas Brømsø, (jonasbn) - C<< <jonasbn@cpan.org> >>
175              
176             =head1 LICENSE AND COPYRIGHT
177              
178             L<Date::Holidays> and related modules are (C) by Jonas Brømsø, (jonasbn)
179             2004-2024
180              
181             Date-Holidays and related modules are released under the Artistic License 2.0
182              
183             =cut