File Coverage

lib/Date/Holidays/Adapter/DE.pm
Criterion Covered Total %
statement 18 38 47.3
branch 1 8 12.5
condition n/a
subroutine 6 8 75.0
pod 2 2 100.0
total 27 56 48.2


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   7 use warnings;
  1         2  
  1         25  
4 1     1   4 use Carp;
  1         1  
  1         19  
5 1     1   4  
  1         1  
  1         43  
6             use base 'Date::Holidays::Adapter';
7 1     1   5  
  1         2  
  1         71  
8             use vars qw($VERSION);
9 1     1   6  
  1         2  
  1         455  
10             my $format = '%#:%m%d';
11              
12             $VERSION = '1.33';
13              
14             # Lifted from Date::Holidays::DE example: feiertage.pl
15             # Ref: https://metacpan.org/source/MSCHMITT/Date-Holidays-DE-1.9/example/feiertage.pl
16             my %holiday_names = (
17             'neuj' => 'Neujahrstag',
18             'hl3k' => 'Hl. 3 Koenige',
19             'weib' => 'Weiberfastnacht',
20             'romo' => 'Rosenmontag',
21             'fadi' => 'Faschingsdienstag',
22             'asmi' => 'Aschermittwoch',
23             'grdo' => 'Gruendonnerstag',
24             'karf' => 'Karfreitag',
25             'kars' => 'Karsamstag',
26             'osts' => 'Ostersonntag',
27             'ostm' => 'Ostermontag',
28             'pfis' => 'Pfingstsonntag',
29             'pfim' => 'Pfingstmontag',
30             'himm' => 'Himmelfahrtstag',
31             'fron' => 'Fronleichnam',
32             '1mai' => 'Maifeiertag',
33             '17ju' => 'Tag der deutschen Einheit (1954-1990)',
34             'mari' => 'Mariae Himmelfahrt',
35             'frie' => 'Augsburger Friedensfest (regional)',
36             '3okt' => 'Tag der deutschen Einheit',
37             'refo' => 'Reformationstag',
38             'alhe' => 'Allerheiligen',
39             'buss' => 'Buss- und Bettag',
40             'votr' => 'Volkstrauertag',
41             'toso' => 'Totensonntag',
42             'adv1' => '1. Advent',
43             'adv2' => '2. Advent',
44             'adv3' => '3. Advent',
45             'adv4' => '4. Advent',
46             'heil' => 'Heiligabend',
47             'wei1' => '1. Weihnachtstag',
48             'wei2' => '2. Weihnachtstag',
49             'silv' => 'Silvester'
50             );
51              
52             my ($self, %params) = @_;
53              
54 0     0 1 0 my $state = $params{'state'} ? $params{'state'} : ['all'];
55              
56 0 0       0 my $holidays;
57              
58 0         0 if ( $params{'year'} ) {
59             $holidays = $self->_transform_arrayref_to_hashref(
60 0 0       0 Date::Holidays::DE::holidays(
61             YEAR => $params{'year'},
62             FORMAT => $format,
63 0         0 WHERE => $state,
64             )
65             );
66             }
67             else {
68             $holidays = $self->_transform_arrayref_to_hashref(
69             Date::Holidays::DE::holidays(
70 0         0 FORMAT => $format,
71             WHERE => $state,
72             )
73             );
74             }
75              
76             return $holidays;
77             }
78 0         0  
79             my ($self, %params) = @_;
80              
81             my $state = $params{'state'} ? $params{'state'} : ['all'];
82 1     1 1 3  
83             my $holidays = Date::Holidays::DE::holidays(
84 1 50       4 YEAR => $params{'year'},
85             FORMAT => $format,
86             WHERE => $state,
87 1         19 );
88              
89             my $holidays_hashref = $self->_transform_arrayref_to_hashref($holidays);
90              
91             my $holiday_date = sprintf('%02s%02s', $params{month}, $params{day});
92 0            
93             my $holiday = $holidays_hashref->{$holiday_date};
94 0            
95             if ($holiday) {
96 0           return $holiday;
97             } else {
98 0 0         return '';
99 0           }
100             }
101 0            
102             my ($self, $arrayref_of_holidays) = @_;
103              
104             my $hashref_of_holidays;
105              
106 0     0     foreach my $entry (@{$arrayref_of_holidays}) {
107             my ($shortname, $key) = split /:/, $entry;
108 0           $hashref_of_holidays->{$key} = $holiday_names{$shortname};
109             }
110 0            
  0            
111 0           return $hashref_of_holidays;
112 0           }
113              
114             1;
115 0            
116              
117             =pod
118              
119             =encoding UTF-8
120              
121             =head1 NAME
122              
123             Date::Holidays::Adapter::DE - an adapter class for Date::Holidays::DE
124              
125             =head1 VERSION
126              
127             This POD describes version 1.33 of Date::Holidays::Adapter::DE
128              
129             =head1 DESCRIPTION
130              
131             The is the adapter class for L<Date::Holidays::DE>.
132              
133             =head1 SUBROUTINES/METHODS
134              
135             =head2 new
136              
137             The constructor, takes a single named argument, B<countrycode>
138              
139             The constructor is inherited from L<Date::Holidays::Adapter>
140              
141             =head2 is_holiday
142              
143             The C<is_holiday> method, takes 3 named arguments, C<year>, C<month> and C<day>
144              
145             Returns an indication of whether the day is a holiday in the calendar of the
146             country referenced by C<countrycode> in the call to the constructor C<new>.
147              
148             =head2 holidays
149              
150             The B<holidays> method, takes a single named argument, B<year>
151              
152             returns a reference to a hash holding the calendar of the country referenced by
153             B<countrycode> in the call to the constructor B<new>.
154              
155             The calendar will spand for a year and the keys consist of B<month> and B<day>
156             concatenated.
157              
158             In addition from version 1.25 the adapter support the B<state> parameter, defaulting to
159             B<'all'>.
160              
161             =head1 DIAGNOSTICS
162              
163             Please refer to DIAGNOSTICS in L<Date::Holidays>
164              
165             =head1 DEPENDENCIES
166              
167             =over
168              
169             =item * L<Date::Holidays::DE>
170              
171             =item * L<Date::Holidays::Adapter>
172              
173             =back
174              
175             =head1 INCOMPATIBILITIES
176              
177             Please refer to INCOMPATIBILITIES in L<Date::Holidays>
178              
179             =head1 BUGS AND LIMITATIONS
180              
181             B<is_holiday> or similar method is not implemented in L<Date::Holidays::DE> as
182             of version 0.06.
183              
184             The adapter does currently not support the complex API of
185             L<Date::Holidays::DE> B<holidays>.
186              
187             Please refer to BUGS AND LIMITATIONS in L<Date::Holidays>
188              
189             =head1 BUG REPORTING
190              
191             Please refer to BUG REPORTING in L<Date::Holidays>
192              
193             =head1 AUTHOR
194              
195             Jonas Brømsø, (jonasbn) - C<< <jonasbn@cpan.org> >>
196              
197             =head1 LICENSE AND COPYRIGHT
198              
199             L<Date::Holidays> and related modules are (C) by Jonas Brømsø, (jonasbn)
200             2004-2022
201              
202             Date-Holidays and related modules are released under the Artistic License 2.0
203              
204             =cut