blib/lib/Calendar/Hebrew.pm

filter: Statementstmt 44.4% 24 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 40.0% 6 / 15 Podpod 62.5% 5 / 8 totaltotal 38.0% 35 / 92 SCAR 29.9
CC
7
Cov
36%
BUILD
30.0
validate_params
12.0
current
2.0
CRAP 20.0
↑ Summary
1 package Calendar::Hebrew;
2  
3 1 $Calendar::Hebrew::VERSION = '0.13';
4 1 $Calendar::Hebrew::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Calendar::Hebrew - Interface to Hebrew Calendar.
9  
10 =head1 VERSION
11  
12 Version 0.13
13  
14 =cut
15  
16 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Date::Hebrew::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 with 'Calendar::Plugin::Renderer';
23  
24 1 ▶use overload q{""} => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 has year => (is => 'rw', predicate => 1);
27 1 has month => (is => 'rw', predicate => 1);
28 0 ▶has date => (is => 'ro', default => sub { Date::Hebrew::Simple->new });
Subroutine __ANON__: not called CC=1 SCAR=1.2
29  
30 sub BUILD {
31 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=5 SCAR=34.0
Pod undocumented
32  
33 0 ▶ $self->date->validate_year($self->year) if $self->has_year;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_year 0 0 0
34 0 ▶ $self->date->validate_hebrew_month($self->month, $self->year) if $self->has_month;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_month 0 0 0
35  
36 0 ▶ unless ($self->has_year && $self->has_month) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->has_year and $self->has_month) 0 0 0
Condition0%0/3
$self->has_year and $self->has_month
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_year and $self->has_month
$self->has_year $self->has_month
Truth table0%0/3
A and B
A= $self->has_yearB= $self->has_month
ABresult
0X0
100
111
37 0 $self->year($self->date->year);
38 0 $self->month($self->date->month);
39 }
40 }
41  
42 =head1 DESCRIPTION
43  
44 The C<Calendar::Hebrew> was released on Sunday 23rd July 2017 to mark the completion
45 of L<1000th consecutive days of releasing to CPAN|http://blogs.perl.org/users/mohammad_s_anwar/2017/07/1000th-consecutive-days-releasing-to-cpan.html>.
46  
47 The Hebrew or Jewish calendar is a lunisolar calendar used today predominantly
48 for Jewish religious observances. It determines the dates for Jewish holidays and
49 the appropriate public reading of Torah portions, yahrzeits (dates to commemorate
50 the death of a relative), and daily Psalm readings, among many ceremonial uses.
51  
52 The Hebrew lunar year is about eleven days shorter than the solar year and uses
53 the 19-year Metonic cycle to bring it into line with the solar year, with the
54 addition of an intercalary month every two or three years, for a total of seven
55 times per 19 years. Even with this intercalation, the average Hebrew calendar
56 year is longer by about 6 minutes and 40 seconds than the current mean tropical
57 year, so that every 216 years the Hebrew calendar will fall a day behind the
58 current mean tropical year; and about every 231 years it will fall a day behind
59 the mean Gregorian calendar year.
60  
61 +--------------------------------------------------------------------------------------------------------+
62 | Tammuz [5777 BE] |
63 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
64 | Yom Rishon | Yom Sheni | Yom Shelishi | Yom Revil | Yom Hamishi | Yom Shishi | Shabbat |
65 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
66 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
67 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
68 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
69 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
70 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
71 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
72 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
73 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
74 | 29 | |
75 +--------------+--------------+--------------+--------------+--------------+--------------+--------------+
76  
77 The package L<App::calendr> provides command line tool C<calendr> to display the
78 supported calendars on the terminal. Support for C<Hebrew Calendar> is provided
79 by L<App::calendr> v0.16 or above.
80  
81 =head1 SYNOPSIS
82  
83 use strict; use warnings;
84 use Calendar::Hebrew;
85  
86 # prints current month calendar
87 print Calendar::Hebrew->new, "\n";
88 print Calendar::Hebrew->new->current, "\n";
89  
90 # prints hebrew month calendar in which the given gregorian date falls in.
91 print Calendar::Hebrew->new->from_gregorian(2015, 1, 14), "\n";
92  
93 # prints hebrew month calendar in which the given julian day falls in.
94 print Calendar::Hebrew->new->from_julian(2457102.5), "\n";
95  
96 # prints current month hebrew calendar in SVG format.
97 print Calendar::Hebrew->new->as_svg;
98  
99 # prints current month hebrewn calendar in text format.
100 print Calendar::Hebrew->new->as_text;
101  
102 =head1 HEBREW MONTHS
103  
104 +-------+-------------------------------------------------------------------+
105 | Month | Hebrew Name |
106 +-------+-------------------------------------------------------------------+
107 | 1 | Nisan |
108 | 2 | Iyar |
109 | 3 | Sivan |
110 | 4 | Tammuz |
111 | 5 | Av |
112 | 6 | Elul |
113 | 7 | Tishrei |
114 | 8 | Cheshvan |
115 | 9 | Kislev |
116 | 10 | Tevet |
117 | 11 | Shevat |
118 | 12 | Adar |
119 +-------+-------------------------------------------------------------------+
120  
121 In leap years (such as 5774) an additional month, Adar I (30 days) is added after
122 Shevat, while the regular Adar is referred to as "Adar II."
123  
124 =head1 HEBREW DAYS
125  
126 +-------+---------------+---------------------------------------------------+
127 | Index | Hebrew Name | English Name |
128 +-------+---------------+---------------------------------------------------+
129 | 0 | Yom Rishon | Sunday |
130 | 1 | Yom Sheni | Monday |
131 | 2 | Yom Shelishi | Tuesday |
132 | 3 | Yom Revil | Wednesday |
133 | 4 | Yom Hamishi | Thursday |
134 | 5 | Yom Shishi | Friday |
135 | 6 | Shabbat | Saturday |
136 +-------+---------------+---------------------------------------------------+
137  
138  
139 =head1 CONSTRUCTOR
140  
141 It expects month and year optionally. By default it gets current Hebrew month and
142 year.
143  
144 =head1 METHODS
145  
146 =head2 current()
147  
148 Returns current month of the Hebrew calendar.
149  
150 =cut
151  
152 sub current {
153 0 ▶ my ($self) = @_;
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
154  
155 0 return $self->as_text($self->date->month, $self->date->year);
156 }
157  
158 =head2 from_gregorian($year, $month, $day)
159  
160 Returns hebrew month calendar in which the given gregorian date falls in.
161  
162 =cut
163  
164 sub from_gregorian {
165 0 ▶ my ($self, $year, $month, $day) = @_;
Subroutine from_gregorian: not called CC=1 SCAR=6.9
Pod documented
166  
167 0 return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
168 }
169  
170 =head2 from_julian($julian_day)
171  
172 Returns hebrew month calendar in which the given julian day falls in.
173  
174 =cut
175  
176 sub from_julian {
177 0 ▶ my ($self, $julian_day) = @_;
Subroutine from_julian: not called CC=1 SCAR=6.9
Pod documented
178  
179 0 my $date = $self->date->from_julian($julian_day);
180 0 return $self->as_text($date->month, $date->year);
181 }
182  
183 =head2 as_svg($month, $year)
184  
185 Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
186 C<$month> and C<$year> missing, it would return current calendar month.
187  
188 =cut
189  
190 sub as_svg {
191 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_svg: not called CC=1 SCAR=6.9
Pod documented
192  
193 0 ($month, $year) = $self->validate_params($month, $year);
194 0 my $date = Date::Hebrew::Simple->new({ year => $year, month => $month, day => 1 });
195  
196 0 return $self->svg_calendar({
197 start_index => $date->day_of_week,
198 month_name => $date->get_month_name,
199 days => $date->days_in_month_year($month, $year),
200 year => $year });
201 }
202  
203 =head2 as_text($month, $year)
204  
205 Returns color coded Hebrew calendar for the given C<$month> and C<$year>. If
206 C<$month> and C<$year> missing, it would return current calendar month.
207  
208 =cut
209  
210 sub as_text {
211 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
212  
213 0 ($month, $year) = $self->validate_params($month, $year);
214 0 my $date = Date::Hebrew::Simple->new({ year => $year, month => $month, day => 1 });
215  
216 0 return $self->text_calendar(
217 {
218 start_index => $date->day_of_week,
219 month_name => $date->get_month_name,
220 days => $date->days_in_month_year($month, $year),
221 day_names => $date->days,
222 year => $year
223 });
224 }
225  
226 sub as_string {
227 0 ▶ my ($self) = @_;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
228  
229 0 return $self->as_text($self->month, $self->year);
230 }
231  
232 #
233 #
234 # Override validate_params()
235 sub validate_params {
236 0 ▶ my ($self, $month, $year) = @_;
Subroutine validate_params: not called CC=3 SCAR=24.8
Pod undocumented
237  
238 0 ▶ $month = $self->month unless defined $month;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $month 0 0 0
239 0 ▶ $year = $self->year unless defined $year;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $year 0 0 0
240  
241 0 $self->date->validate_year($year);
242 0 $self->date->validate_hebrew_month($month, $year);
243  
244 0 return ($month, $year);
245 }
246  
247 =head1 AUTHOR
248  
249 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
250  
251 =head1 REPOSITORY
252  
253 L<https://github.com/manwar/Calendar-Hebrew>
254  
255 =head1 ACKNOWLEDGEMENTS
256  
257 The C<Calendar::Hebrew> namespace was originally owned by Yitzchak Scott-Thoennes.
258 Yitzchak has kindly transferred the ownership to me, so that I can keep working on
259 it.
260  
261 =head1 SEE ALSO
262  
263 =over 4
264  
265 =item L<Calendar::Bahai>
266  
267 =item L<Calendar::Hijri>
268  
269 =item L<Calendar::Gregorian>
270  
271 =item L<Calendar::Persian>
272  
273 =item L<Calendar::Saka>
274  
275 =back
276  
277 =head1 BUGS
278  
279 Please report any bugs or feature requests to C<bug-calendar-hebrew at rt.cpan.org>,
280 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Hebrew>.
281 I will be notified, and then you'll automatically be notified of progress on your
282 bug as I make changes.
283  
284 =head1 SUPPORT
285  
286 You can find documentation for this module with the perldoc command.
287  
288 perldoc Calendar::Hebrew
289  
290 You can also look for information at:
291  
292 =over 4
293  
294 =item * RT: CPAN's request tracker
295  
296 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Hebrew>
297  
298 =item * AnnoCPAN: Annotated CPAN documentation
299  
300 L<http://annocpan.org/dist/Calendar-Hebrew>
301  
302 =item * CPAN Ratings
303  
304 L<http://cpanratings.perl.org/d/Calendar-Hebrew>
305  
306 =item * Search CPAN
307  
308 L<http://search.cpan.org/dist/Calendar-Hebrew/>
309  
310 =back
311  
312 =head1 LICENSE AND COPYRIGHT
313  
314 Copyright (C) 2017 Mohammad S Anwar.
315  
316 This program is free software; you can redistribute it and/or modify it under
317 the terms of the the Artistic License (2.0). You may obtain a copy of the full
318 license at:
319  
320 L<http://www.perlfoundation.org/artistic_license_2_0>
321  
322 Any use, modification, and distribution of the Standard or Modified Versions is
323 governed by this Artistic License.By using, modifying or distributing the Package,
324 you accept this license. Do not use, modify, or distribute the Package, if you do
325 not accept this license.
326  
327 If your Modified Version has been derived from a Modified Version made by someone
328 other than you,you are nevertheless required to ensure that your Modified Version
329 complies with the requirements of this license.
330  
331 This license does not grant you the right to use any trademark, service mark,
332 tradename, or logo of the Copyright Holder.
333  
334 This license includes the non-exclusive, worldwide, free-of-charge patent license
335 to make, have made, use, offer to sell, sell, import and otherwise transfer the
336 Package with respect to any patent claims licensable by the Copyright Holder that
337 are necessarily infringed by the Package. If you institute patent litigation
338 (including a cross-claim or counterclaim) against any party alleging that the
339 Package constitutes direct or contributory patent infringement,then this Artistic
340 License to you shall terminate on the date that such litigation is filed.
341  
342 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
343 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
344 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
345 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
346 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
347 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
348 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
349  
350 =cut
351  
352 1 1; # End of Calendar::Hebrew
↑ Summary