File Coverage

blib/lib/Calendar/Plugin/Renderer.pm
Criterion Covered Total %
statement 20 45 44.4
branch 0 6 0.0
condition 0 3 0.0
subroutine 7 10 70.0
pod 3 3 100.0
total 30 67 44.7


line stmt bran cond sub pod time code
1             package Calendar::Plugin::Renderer;
2              
3             $Calendar::Plugin::Renderer::VERSION = '0.12';
4             $Calendar::Plugin::Renderer::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             Calendar::Plugin::Renderer - Role to render calendar.
9              
10             =head1 VERSION
11              
12             Version 0.12
13              
14             =cut
15              
16 3     3   14646 use 5.006;
  3         6  
17 3     3   1501 use Data::Dumper;
  3         18919  
  3         167  
18 3     3   1209 use Term::ANSIColor::Markup;
  3         31734  
  3         12  
19              
20 3     3   1442 use Calendar::Plugin::Renderer::Text;
  3         8  
  3         92  
21 3     3   1548 use Calendar::Plugin::Renderer::SVG;
  3         5  
  3         86  
22              
23 3     3   1270 use Moo::Role;
  3         16354  
  3         14  
24 3     3   668 use namespace::clean;
  3         4  
  3         14  
25              
26             =head1 DESCRIPTION
27              
28             Moo Role to render Calendar, currently in SVG and Text format only. This role is
29             taken by the following calendars:
30              
31             =over 4
32              
33             =item * L
34              
35             =item * L
36              
37             =item * L
38              
39             =item * L
40              
41             =item * L
42              
43             =back
44              
45             =head1 SYNOPSIS
46              
47             package Cal;
48              
49             use Moo;
50             use namespace::clean;
51             with 'Calendar::Plugin::Renderer';
52              
53             package main;
54              
55             use strict; use warnings;
56             use Cal;
57              
58             my $cal = Cal->new;
59             print $cal->svg_calendar({
60             start_index => 5,
61             month_name => 'January',
62             days => 31,
63             year => 2016 });
64              
65             print $cal->text_calendar({
66             start_index => 5,
67             month_name => 'January',
68             days => 31,
69             year => 2016 });
70              
71             =head1 METHODS
72              
73             =head2 text_calendar(\%params)
74              
75             Returns the color coded calendar as a scalar string.
76              
77             Expected paramaeters are as below:
78              
79             +-------------+-------------------------------------------------------------+
80             | Key | Description |
81             +-------------+-------------------------------------------------------------+
82             | start_index | Index of first day of the month. (0-Sun,1-Mon etc) |
83             | month_name | Calendar month. |
84             | days | Days count in the month. |
85             | year | Calendar year. |
86             | day_names | Ref to a list of day name starting with Sunday. (Optional) |
87             +-------------+-------------------------------------------------------------+
88              
89             =cut
90              
91             sub text_calendar {
92 0     0 1   my ($self, $params) = @_;
93              
94 0 0         unless (exists $params->{day_names}) {
95 0           $params->{day_names} = [qw(Sun Mon Tue Wed Thu Fri Sat)];
96             }
97              
98 0           my $text = Calendar::Plugin::Renderer::Text->new($params);
99              
100 0           my $line1 = $text->get_dashed_line;
101 0           my $line2 = $text->get_month_header;
102 0           my $line3 = $text->get_blocked_line;
103 0           my $line4 = $text->get_day_header;
104 0           my $empty = $text->get_empty_space;
105 0           my $dates = $text->get_dates;
106              
107 0           my $calendar = join("\n", $line1, $line2, $line3, $line4, $line3, $empty.$dates)."\n";
108              
109 0           return Term::ANSIColor::Markup->colorize($calendar);
110             }
111              
112             =head2 svg_calendar(\%params)
113              
114             Returns the requested calendar month in SVG format.
115              
116             Expected paramaeters are as below:
117              
118             +---------------+-----------------------------------------------------------+
119             | Key | Description |
120             +---------------+-----------------------------------------------------------+
121             | start_index | Index of first day of the month. (0-Sun,1-Mon etc) |
122             | month_name | Calendar month. |
123             | days | Days count in the month. |
124             | year | Calendar year. |
125             | adjust_height | Adjust height of the rows in Calendar. (Optional) |
126             +---------------+-----------------------------------------------------------+
127              
128             =cut
129              
130             sub svg_calendar {
131 0     0 1   my ($self, $params) = @_;
132              
133 0           my $svg = Calendar::Plugin::Renderer::SVG->new($params);
134 0           $svg->process;
135              
136 0           return $svg->as_string;
137             }
138              
139             =head2 validate_params($month, $year)
140              
141             Validate given C<$month> and C<$year> as per the Calendar guidelines. C<$month>
142             can be "name" or "integer". If C<$month> is passed as "name" then it converts it
143             it into its "integer" equivalent. Both parameters are optional. In case they are
144             missing, it returns the current month and year of the selected calendar.
145              
146             =cut
147              
148             sub validate_params {
149 0     0 1   my ($self, $month, $year) = @_;
150              
151 0 0 0       if (defined $month && defined $year) {
152 0           $self->date->validate_month($month);
153 0           $self->date->validate_year($year);
154              
155 0 0         if ($month !~ /^\d+$/) {
156 0           $month = $self->date->get_month_number($month);
157             }
158             }
159             else {
160 0           $month = $self->month;
161 0           $year = $self->year;
162             }
163              
164 0           return ($month, $year);
165             }
166              
167             =head1 AUTHOR
168              
169             Mohammad S Anwar, C<< >>
170              
171             =head1 REPOSITORY
172              
173             L
174              
175             =head1 SEE ALSO
176              
177             L
178              
179             =head1 ACKNOWLEDGEMENT
180              
181             Inspired by the package L so that it can be used as a plugin.
182              
183             =head1 BUGS
184              
185             Please report any bugs / feature requests to C,
186             or through the web interface at L.
187             I will be notified, and then you'll automatically be notified of progress on your
188             bug as I make changes.
189              
190             =head1 SUPPORT
191              
192             You can find documentation for this module with the perldoc command.
193              
194             perldoc Calendar::Plugin::Renderer
195              
196             You can also look for information at:
197              
198             =over 4
199              
200             =item * RT: CPAN's request tracker
201              
202             L
203              
204             =item * AnnoCPAN: Annotated CPAN documentation
205              
206             L
207              
208             =item * CPAN Ratings
209              
210             L
211              
212             =item * Search CPAN
213              
214             L
215              
216             =back
217              
218             =head1 LICENSE AND COPYRIGHT
219              
220             Copyright (C) 2015 - 2016 Mohammad S Anwar.
221              
222             This program is free software; you can redistribute it and / or modify it under
223             the terms of the the Artistic License (2.0). You may obtain a copy of the full
224             license at:
225              
226             L
227              
228             Any use, modification, and distribution of the Standard or Modified Versions is
229             governed by this Artistic License.By using, modifying or distributing the Package,
230             you accept this license. Do not use, modify, or distribute the Package, if you do
231             not accept this license.
232              
233             If your Modified Version has been derived from a Modified Version made by someone
234             other than you,you are nevertheless required to ensure that your Modified Version
235             complies with the requirements of this license.
236              
237             This license does not grant you the right to use any trademark, service mark,
238             tradename, or logo of the Copyright Holder.
239              
240             This license includes the non-exclusive, worldwide, free-of-charge patent license
241             to make, have made, use, offer to sell, sell, import and otherwise transfer the
242             Package with respect to any patent claims licensable by the Copyright Holder that
243             are necessarily infringed by the Package. If you institute patent litigation
244             (including a cross-claim or counterclaim) against any party alleging that the
245             Package constitutes direct or contributory patent infringement,then this Artistic
246             License to you shall terminate on the date that such litigation is filed.
247              
248             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
249             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
250             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
251             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
252             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
253             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
254             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
255              
256             =cut
257              
258             1; # End of Calendar::Plugin::Renderer