File Coverage

lib/Date/Holidays/Adapter/ES.pm
Criterion Covered Total %
statement 17 53 32.0
branch 0 14 0.0
condition 0 6 0.0
subroutine 6 7 85.7
pod 2 2 100.0
total 25 82 30.4


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