File Coverage

blib/lib/Calendar/Plugin/Renderer.pm
Criterion Covered Total %
statement 20 36 55.5
branch 0 2 0.0
condition n/a
subroutine 7 9 77.7
pod 2 2 100.0
total 29 49 59.1


line stmt bran cond sub pod time code
1             package Calendar::Plugin::Renderer;
2              
3             $Calendar::Plugin::Renderer::VERSION = '0.10';
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.10
13              
14             =cut
15              
16 1     1   13108 use 5.006;
  1         2  
17 1     1   487 use Data::Dumper;
  1         6085  
  1         44  
18 1     1   375 use Term::ANSIColor::Markup;
  1         10471  
  1         5  
19              
20 1     1   401 use Calendar::Plugin::Renderer::Text;
  1         3  
  1         28  
21 1     1   462 use Calendar::Plugin::Renderer::SVG;
  1         2  
  1         28  
22              
23 1     1   403 use Moo::Role;
  1         5294  
  1         4  
24 1     1   207 use namespace::clean;
  1         1  
  1         4  
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             =head1 AUTHOR
140              
141             Mohammad S Anwar, C<< >>
142              
143             =head1 REPOSITORY
144              
145             L
146              
147             =head1 SEE ALSO
148              
149             L
150              
151             =head1 ACKNOWLEDGEMENT
152              
153             Inspired by the package L so that it can be used as a plugin.
154              
155             =head1 BUGS
156              
157             Please report any bugs / feature requests to C,
158             or through the web interface at L.
159             I will be notified, and then you'll automatically be notified of progress on your
160             bug as I make changes.
161              
162             =head1 SUPPORT
163              
164             You can find documentation for this module with the perldoc command.
165              
166             perldoc Calendar::Plugin::Renderer
167              
168             You can also look for information at:
169              
170             =over 4
171              
172             =item * RT: CPAN's request tracker
173              
174             L
175              
176             =item * AnnoCPAN: Annotated CPAN documentation
177              
178             L
179              
180             =item * CPAN Ratings
181              
182             L
183              
184             =item * Search CPAN
185              
186             L
187              
188             =back
189              
190             =head1 LICENSE AND COPYRIGHT
191              
192             Copyright (C) 2015 - 2016 Mohammad S Anwar.
193              
194             This program is free software; you can redistribute it and / or modify it under
195             the terms of the the Artistic License (2.0). You may obtain a copy of the full
196             license at:
197              
198             L
199              
200             Any use, modification, and distribution of the Standard or Modified Versions is
201             governed by this Artistic License.By using, modifying or distributing the Package,
202             you accept this license. Do not use, modify, or distribute the Package, if you do
203             not accept this license.
204              
205             If your Modified Version has been derived from a Modified Version made by someone
206             other than you,you are nevertheless required to ensure that your Modified Version
207             complies with the requirements of this license.
208              
209             This license does not grant you the right to use any trademark, service mark,
210             tradename, or logo of the Copyright Holder.
211              
212             This license includes the non-exclusive, worldwide, free-of-charge patent license
213             to make, have made, use, offer to sell, sell, import and otherwise transfer the
214             Package with respect to any patent claims licensable by the Copyright Holder that
215             are necessarily infringed by the Package. If you institute patent litigation
216             (including a cross-claim or counterclaim) against any party alleging that the
217             Package constitutes direct or contributory patent infringement,then this Artistic
218             License to you shall terminate on the date that such litigation is filed.
219              
220             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
221             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
222             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
223             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
224             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
225             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
226             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
227              
228             =cut
229              
230             1; # End of Calendar::Plugin::Renderer