line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Namedays::Simple; |
2
|
3
|
|
|
3
|
|
69163
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
104
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
BEGIN { |
5
|
3
|
|
|
3
|
|
12
|
use Exporter (); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
51
|
|
6
|
3
|
|
|
3
|
|
14
|
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
356
|
|
7
|
3
|
|
|
3
|
|
7
|
$VERSION = 0.01; |
8
|
3
|
|
|
|
|
47
|
@ISA = qw (Exporter); |
9
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
10
|
3
|
|
|
|
|
5
|
@EXPORT = qw (); |
11
|
3
|
|
|
|
|
13
|
@EXPORT_OK = qw (); |
12
|
3
|
|
|
|
|
1410
|
%EXPORT_TAGS = (); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#################################################################################### |
16
|
|
|
|
|
|
|
# Create object - we do nothing with the parameters now (maybe in a later version) |
17
|
|
|
|
|
|
|
#################################################################################### |
18
|
|
|
|
|
|
|
sub new { |
19
|
3
|
|
|
3
|
0
|
70
|
my ($class, %parameters) = @_; |
20
|
3
|
|
33
|
|
|
27
|
my $self = bless ({}, ref ($class) || $class); |
21
|
3
|
|
|
|
|
11
|
return ($self); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
########################################################### |
26
|
|
|
|
|
|
|
# Input: month, day, [year] |
27
|
|
|
|
|
|
|
# A list of names is returned. |
28
|
|
|
|
|
|
|
# Year is optional, but if you do not provide it, leap |
29
|
|
|
|
|
|
|
# years are not taken into consideration! |
30
|
|
|
|
|
|
|
########################################################### |
31
|
|
|
|
|
|
|
sub getNames { |
32
|
2
|
|
|
2
|
0
|
552
|
my ($self, $month, $day, $year) = @_; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# some calendars handle leap-years in a special way... like |
35
|
|
|
|
|
|
|
# the Hungarian, which is totally insane |
36
|
2
|
|
|
|
|
5
|
my $leapyearmonth = 0; |
37
|
2
|
50
|
66
|
|
|
17
|
my $leapyearmonth = 1 if ($year && (not ($year % 4) ) && ($month == 2)); |
|
|
|
33
|
|
|
|
|
38
|
|
|
|
|
|
|
# note: this is a VERY lame leap-year calculation here... |
39
|
|
|
|
|
|
|
|
40
|
2
|
50
|
|
|
|
5
|
if ($leapyearmonth) { |
41
|
0
|
|
|
|
|
0
|
($month, $day) = $self->leapYear($month, $day) |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
2
|
|
|
|
|
11
|
my $namedays = $self->_getNameDays; |
45
|
2
|
|
|
|
|
3
|
return @{$namedays->[$month-1]->[$day-1]}; |
|
2
|
|
|
|
|
11
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
############################################################################ |
49
|
|
|
|
|
|
|
# Leap year, default implementation: does nothing. |
50
|
|
|
|
|
|
|
############################################################################ |
51
|
|
|
|
|
|
|
sub leapYear { |
52
|
0
|
|
|
0
|
0
|
0
|
my ($self, $year, $month, $day) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return ($month, $day); # default: don't change; some override this... |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
############################################################################ |
58
|
|
|
|
|
|
|
# Returns all namedays in an arrayref |
59
|
|
|
|
|
|
|
############################################################################ |
60
|
|
|
|
|
|
|
sub _getNameDays { |
61
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# We simply "cache" namedays data |
64
|
2
|
100
|
|
|
|
11
|
return $self->{NAMEDAYS} if ($self->{NAMEDAYS}); |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
|
|
2
|
my $namedays = []; |
67
|
1
|
|
|
|
|
3
|
my $in = $self->processNames; |
68
|
1
|
|
|
|
|
124
|
my (@lines) = split (/\n/, $in); |
69
|
1
|
|
|
|
|
10
|
foreach my $line (@lines) { |
70
|
366
|
|
|
|
|
1252
|
my ($month, $day, $names) = ($line =~ /^(\d+)\.(\d+)\.(\S+)$/); |
71
|
366
|
|
|
|
|
420
|
chomp ($names); |
72
|
366
|
|
|
|
|
628
|
my (@names) = split (/,/, $names); |
73
|
366
|
|
|
|
|
395
|
$month--; |
74
|
366
|
|
|
|
|
308
|
$day--; |
75
|
366
|
100
|
|
|
|
635
|
$namedays->[$month] = [] if (not $namedays->[$month]); |
76
|
366
|
|
|
|
|
694
|
$namedays->[$month]->[$day] = \@names; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1
|
|
|
|
|
4
|
$self->{NAMEDAYS} = $namedays; # "cache" for later use |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
24
|
return $namedays; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub processNames { |
85
|
1
|
|
|
1
|
0
|
493
|
die ("Hi, I am Date::Namedays::Simpler. Sorry, you must provide a 'processNames' sub in subclasses!"); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
########################################### main pod documentation begin ## |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Date::Namedays::Simple - simple base class for getting namedays for a given date. |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
use Date::Namedays::Simple::Your_Language_Module_Here; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# create an instance |
100
|
|
|
|
|
|
|
# Date::Namedays::Simple is abstract, so must use a subclass |
101
|
|
|
|
|
|
|
my $nd = new Date::Namedays::Simple::Hungarian; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# get (all!) names for the year 2001, 24th of July |
104
|
|
|
|
|
|
|
my (@names) = $nd->getNames(7,24,2001); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
# Now simply print them |
107
|
|
|
|
|
|
|
my $namestoday = join (',',@names); |
108
|
|
|
|
|
|
|
print $namestoday; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 DESCRIPTION |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
In many countries, people not only celebrate their birthdays annually, but there is also the concept of "nameday". |
114
|
|
|
|
|
|
|
Calendars in these countries (e.g. Hungary) contain one ore more names for each day - the day on which a person with |
115
|
|
|
|
|
|
|
the given first name celebrate his/her nameday. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
This module is here simply to aid you to get the namedays for a date. You simply supply the year, month and day, and |
118
|
|
|
|
|
|
|
the corresponding names are returned. It is as simple as that. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This module uses no external modules. It does not export anything - I wanted to keep it as simple as possible. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Please note: THIS MODULE IS ALPHA PHASE! It works, but I need some feedback. (Send feedback!) The methods and their |
123
|
|
|
|
|
|
|
parameters can change any time! |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Note: names are stored in a human readable format. Because of this, they are parsed at runtime. This takes some |
126
|
|
|
|
|
|
|
time obviously - just don't worry about it, we "cache" that in $self, and actually that's why this module must be |
127
|
|
|
|
|
|
|
instanteniated, that's why we have instance methods instead of class methods. |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Date::Namedays::Simple is an abstract class, it is always subclassed, for example to |
131
|
|
|
|
|
|
|
Date::Namedays::Simple::Hungarian. Subclasses must implement the "processNames()" method. This method shall return |
132
|
|
|
|
|
|
|
a string(!) in the following format: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1.1.name1,name2,...,nameN |
135
|
|
|
|
|
|
|
1.2.name1,name2,...,nameN |
136
|
|
|
|
|
|
|
... |
137
|
|
|
|
|
|
|
12.31.name1,name2,...,nameN |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Which is more precisely a "\n" separated list of the following lines: |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
$month.$day.$name1[,$name2,...,$nameN]\n |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
See Date::Namedays::Simple::Hungarian for example! |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 USAGE |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
See SYNOPSIS. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head1 BUGS |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
None so far... send bugreports! |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Ask the author. Only bugs concerning this module, please! |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 AUTHOR |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Csongor Fagyal |
163
|
|
|
|
|
|
|
csongorNOSPAMREMOVEME@fagyal.com |
164
|
|
|
|
|
|
|
http://www.conceptonline.com/about |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 COPYRIGHT |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This program is free software; you can redistribute |
169
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
The full text of the license can be found in the |
172
|
|
|
|
|
|
|
LICENSE file included with this module. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 SEE ALSO |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
perl(1). |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
############################################# main pod documentation end ## |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
################################################ subroutine header begin ## |
185
|
|
|
|
|
|
|
# |
186
|
|
|
|
|
|
|
#=head2 sample_function |
187
|
|
|
|
|
|
|
# |
188
|
|
|
|
|
|
|
# Usage : How to use this function/method |
189
|
|
|
|
|
|
|
# Purpose : What it does |
190
|
|
|
|
|
|
|
# Returns : What it returns |
191
|
|
|
|
|
|
|
# Argument : What it wants to know |
192
|
|
|
|
|
|
|
# Throws : Exceptions and other anomolies |
193
|
|
|
|
|
|
|
# Comments : This is a sample subroutine header. |
194
|
|
|
|
|
|
|
# : It is polite to include more pod and fewer comments. |
195
|
|
|
|
|
|
|
# |
196
|
|
|
|
|
|
|
#See Also : |
197
|
|
|
|
|
|
|
# |
198
|
|
|
|
|
|
|
#=cut |
199
|
|
|
|
|
|
|
# |
200
|
|
|
|
|
|
|
################################################## subroutine header end ## |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; # boinggg |
205
|
|
|
|
|
|
|
__END__ |