File Coverage

blib/lib/Date/Holidays/Adapter/DE.pm
Criterion Covered Total %
statement 15 38 39.4
branch 0 8 0.0
condition n/a
subroutine 5 8 62.5
pod 2 2 100.0
total 22 56 39.2


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