blib/lib/Calendar/Persian.pm

filter: Statementstmt 50.0% 24 / 48 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 6 / 14 Podpod 71.4% 5 / 7 totaltotal 43.7% 35 / 80 CC 5 SCAR 22.4
CC
5
Cov
42%
BUILD
30.0
current
2.0
from_gregorian
2.0
CRAP 9.4
↑ Summary
1 package Calendar::Persian;
2  
3 4 $Calendar::Persian::VERSION = '0.37';
4 4 $Calendar::Persian::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Calendar::Persian - Interface to Persian Calendar.
9  
10 =head1 VERSION
11  
12 Version 0.37
13  
14 =cut
15  
16 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 ▶use Date::Persian::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 with 'Calendar::Plugin::Renderer';
23  
24 4 ▶use overload q{""} => 'as_string', fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 4 has year => (is => 'rw', predicate => 1);
27 4 has month => (is => 'rw', predicate => 1);
28 0 ▶has date => (is => 'ro', default => sub { Date::Persian::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_month($self->month) 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 Persian calendar is solar, with the particularity that the year defined by
45 two successive, apparent passages of the Sun through the vernal (spring)
46 equinox. It is based on precise astronomical observations, and moreover uses a
47 sophisticated intercalation system, which makes it more accurate than its younger
48 European counterpart,the Gregorian calendar. It is currently used in Iran as the
49 official calendar of the country. The starting point of the current Iranian
50 calendar is the vernal equinox occurred on Friday March 22 of the year A.D. 622.
51 Persian Calendar for the month of Farvadin year 1390.
52  
53 +---------------------------------------------------------------------------------------------------------------+
54 | Farvardin [1394 BE] |
55 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
56 | Yekshanbeh | Doshanbeh | Seshhanbeh | Chaharshanbeh | Panjshanbeh | Jomeh | Shanbeh |
57 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
58 | | 1 |
59 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
60 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
61 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
62 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
63 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
64 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
65 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
66 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
67 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
68 | 30 | 31 | |
69 +---------------+---------------+---------------+---------------+---------------+---------------+---------------+
70  
71 The package L<App::calendr> provides command line tool C<calendr> to display the
72 supported calendars on the terminal.
73  
74 =head1 SYNOPSIS
75  
76 use strict; use warnings;
77 use Calendar::Persian;
78  
79 # prints current month calendar
80 print Calendar::Persian->new, "\n";
81 print Calendar::Persian->new->current, "\n";
82  
83 # prints persian month calendar for the first month of year 1394.
84 print Calendar::Persian->new({ month => 1, year => 1394 }), "\n";
85  
86 # prints persian month calendar in which the given gregorian date falls in.
87 print Calendar::Persian->new->from_gregorian(2015, 1, 14), "\n";
88  
89 # prints persian month calendar in which the given julian date falls in.
90 print Calendar::Persian->new->from_julian(2457102.5), "\n";
91  
92 # prints current month persian calendar in SVG format.
93 print Calendar::Persian->new->as_svg;
94  
95 # prints current month persian calendar in text format.
96 print Calendar::Persian->new->as_text;
97  
98 =head1 PERSIAN MONTHS
99  
100 +-------+-------------------------------------------------------------------+
101 | Month | Persian Name |
102 +-------+-------------------------------------------------------------------+
103 | 1 | Farvardin |
104 | 2 | Ordibehesht |
105 | 3 | Xordad |
106 | 4 | Tir |
107 | 5 | Amordad |
108 | 6 | Sahrivar |
109 | 7 | Mehr |
110 | 8 | Aban |
111 | 9 | Azar |
112 | 10 | Dey |
113 | 11 | Bahman |
114 | 12 | Esfand |
115 +-------+-------------------------------------------------------------------+
116  
117 =head1 PERSIAN DAYS
118  
119 +-------+---------------+---------------------------------------------------+
120 | Index | Persian Name | English Name |
121 +-------+---------------+---------------------------------------------------+
122 | 0 | Yekshanbeh | Sunday |
123 | 1 | Doshanbeh | Monday |
124 | 2 | Seshhanbeh | Tuesday |
125 | 3 | Chaharshanbeh | Wednesday |
126 | 4 | Panjshanbeh | Thursday |
127 | 5 | Jomeh | Friday |
128 | 6 | Shanbeh | Saturday |
129 +-------+---------------+---------------------------------------------------+
130  
131 =head1 CONSTRUCTOR
132  
133 It expects month and year optionally.By default it gets current Persian month and
134 year.
135  
136 =head1 METHODS
137  
138 =head2 current()
139  
140 Returns current month of the Persian calendar.
141  
142 =cut
143  
144 sub current {
145 0 ▶ my ($self) = @_;
Subroutine current: not called CC=1 SCAR=6.9
Pod documented
146  
147 0 return $self->as_text($self->date->month, $self->date->year);
148 }
149  
150 =head2 from_gregorian($year, $month, $day)
151  
152 Returns persian month calendar in which the given gregorian date falls in.
153  
154 =cut
155  
156 sub from_gregorian {
157 0 ▶ my ($self, $year, $month, $day) = @_;
Subroutine from_gregorian: not called CC=1 SCAR=6.9
Pod documented
158  
159 0 return $self->from_julian($self->date->gregorian_to_julian($year, $month, $day));
160 }
161  
162 =head2 from_julian($julian_date)
163  
164 Returns persian month calendar in which the given julian date falls in.
165  
166 =cut
167  
168 sub from_julian {
169 0 ▶ my ($self, $julian_date) = @_;
Subroutine from_julian: not called CC=1 SCAR=6.9
Pod documented
170  
171 0 my $date = $self->date->from_julian($julian_date);
172 0 return $self->as_text($date->month, $date->year);
173 }
174  
175 =head2 as_svg($month, $year)
176  
177 Returns calendar for the given C<$month> and C<$year> rendered in SVG format. If
178 C<$month> and C<$year> missing, it would return current calendar month.
179  
180 =cut
181  
182 sub as_svg {
183 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_svg: not called CC=1 SCAR=6.9
Pod documented
184  
185 0 ($month, $year) = $self->validate_params($month, $year);
186 0 my $date = Date::Persian::Simple->new({ year => $year, month => $month, day => 1 });
187  
188 0 return $self->svg_calendar({
189 start_index => $date->day_of_week,
190 month_name => $date->get_month_name,
191 days => $date->days_in_month_year($month, $year),
192 year => $year });
193 }
194  
195 =head2 as_text($month, $year)
196  
197 Returns color coded Persian calendar for the given C<$month> and C<$year>. If
198 C<$month> and C<$year> missing, it would return current calendar month.
199  
200 =cut
201  
202 sub as_text {
203 0 ▶ my ($self, $month, $year) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod documented
204  
205 0 ($month, $year) = $self->validate_params($month, $year);
206 0 my $date = Date::Persian::Simple->new({ year => $year, month => $month, day => 1 });
207  
208 0 return $self->text_calendar(
209 {
210 start_index => $date->day_of_week,
211 month_name => $date->get_month_name,
212 days => $date->days_in_month_year($month, $year),
213 day_names => $date->days,
214 year => $year
215 });
216 }
217  
218 sub as_string {
219 0 ▶ my ($self) = @_;
Subroutine as_string: not called CC=1 SCAR=6.9
Pod undocumented
220  
221 0 return $self->as_text($self->month, $self->year);
222 }
223  
224 =head1 AUTHOR
225  
226 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
227  
228 =head1 REPOSITORY
229  
230 L<https://github.com/manwar/Calendar-Persian>
231  
232 =head1 SEE ALSO
233  
234 =over 4
235  
236 =item L<Calendar::Bahai>
237  
238 =item L<Calendar::Hijri>
239  
240 =item L<Calendar::Gregorian>
241  
242 =item L<Calendar::Saka>
243  
244 =back
245  
246 =head1 BUGS
247  
248 Please report any bugs or feature requests to C<bug-calendar-persian at rt.cpan.org>,
249 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Persian>.
250 I will be notified, and then you'll automatically be notified of progress on your
251 bug as I make changes.
252  
253 =head1 SUPPORT
254  
255 You can find documentation for this module with the perldoc command.
256  
257 perldoc Calendar::Persian
258  
259 You can also look for information at:
260  
261 =over 4
262  
263 =item * RT: CPAN's request tracker
264  
265 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Persian>
266  
267 =item * AnnoCPAN: Annotated CPAN documentation
268  
269 L<http://annocpan.org/dist/Calendar-Persian>
270  
271 =item * CPAN Ratings
272  
273 L<http://cpanratings.perl.org/d/Calendar-Persian>
274  
275 =item * Search CPAN
276  
277 L<http://search.cpan.org/dist/Calendar-Persian/>
278  
279 =back
280  
281 =head1 LICENSE AND COPYRIGHT
282  
283 Copyright (C) 2011 - 2016 Mohammad S Anwar.
284  
285 This program is free software; you can redistribute it and/or modify it under
286 the terms of the the Artistic License (2.0). You may obtain a copy of the full
287 license at:
288  
289 L<http://www.perlfoundation.org/artistic_license_2_0>
290  
291 Any use, modification, and distribution of the Standard or Modified Versions is
292 governed by this Artistic License.By using, modifying or distributing the Package,
293 you accept this license. Do not use, modify, or distribute the Package, if you do
294 not accept this license.
295  
296 If your Modified Version has been derived from a Modified Version made by someone
297 other than you,you are nevertheless required to ensure that your Modified Version
298 complies with the requirements of this license.
299  
300 This license does not grant you the right to use any trademark, service mark,
301 tradename, or logo of the Copyright Holder.
302  
303 This license includes the non-exclusive, worldwide, free-of-charge patent license
304 to make, have made, use, offer to sell, sell, import and otherwise transfer the
305 Package with respect to any patent claims licensable by the Copyright Holder that
306 are necessarily infringed by the Package. If you institute patent litigation
307 (including a cross-claim or counterclaim) against any party alleging that the
308 Package constitutes direct or contributory patent infringement,then this Artistic
309 License to you shall terminate on the date that such litigation is filed.
310  
311 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
312 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
313 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
314 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
315 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
316 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
317 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
318  
319 =cut
320  
321 4 1; # End of Calendar::Persian
↑ Summary