| 1 | package Calendar::Plugin::Renderer; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | $Calendar::Plugin::Renderer::VERSION = '0.13'; | |||||||||||||||||||||||||||
| 4 | 3 | $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.13 | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =cut | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use 5.006; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Term::ANSIColor::Markup; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Calendar::Plugin::Renderer::Text; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Calendar::Plugin::Renderer::SVG; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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<Calendar::Bahai> | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =item * L<Calendar::Gregorian> | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =item * L<Calendar::Hijri> | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =item * L<Calendar::Persian> | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =item * L<Calendar::Saka> | ||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
text_calendar: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | unless (exists $params->{day_names}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
svg_calendar: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 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 | ▶ | my ($self, $month, $year) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate_params: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | if (defined $month && defined $year) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $month and defined $year
MC/DC0%0/2
defined $month and defined $year
defined $month
defined $year
Truth table0%0/3
A and B
A= defined $monthB= defined $year
| |||||||||||||||||||||||||||||
| 152 | 0 | $self->date->validate_month($month); | |||||||||||||||||||||||||||
| 153 | 0 | $self->date->validate_year($year); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 0 | ▶ | if ($month !~ /^\d+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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<< <mohammad.anwar at yahoo.com> >> | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | =head1 REPOSITORY | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | L<https://github.com/manwar/Calendar-Plugin-Renderer> | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | L<SVG::Calendar> | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head1 ACKNOWLEDGEMENT | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Inspired by the package L<SVG::Calendar> so that it can be used as a plugin. | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head1 BUGS | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | Please report any bugs / feature requests to C<bug-calendar-plugin-renderer at rt.cpan.org>, | ||||||||||||||||||||||||||||
| 186 | or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Plugin-Renderer>. | ||||||||||||||||||||||||||||
| 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Plugin-Renderer> | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | L<http://annocpan.org/dist/Calendar-Plugin-Renderer> | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | L<http://cpanratings.perl.org/d/Calendar-Plugin-Renderer> | ||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | L<http://search.cpan.org/dist/Calendar-Plugin-Renderer/> | ||||||||||||||||||||||||||||
| 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<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||||||||||||||||||||
| 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 | 3 | 1; # End of Calendar::Plugin::Renderer | |||||||||||||||||||||||||||