blib/lib/Calendar/Gregorian.pm

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