File Coverage

blib/lib/Template/Plugin/Calendar/Simple.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition n/a
subroutine 10 10 100.0
pod 3 3 100.0
total 46 46 100.0


line stmt bran cond sub pod time code
1             package Template::Plugin::Calendar::Simple;
2 4     4   934155 use strict;
  4         11  
  4         202  
3 4     4   25 use warnings FATAL => 'all';
  4         8  
  4         359  
4             our $VERSION = '1.04';
5              
6 4     4   3487 use Calendar::Simple;
  4         2855733  
  4         580  
7 4     4   3216 use Template::Plugin;
  4         14511  
  4         257  
8 4     4   2519 use Template::Iterator;
  4         11331  
  4         187  
9 4     4   38 use Template::Exception;
  4         9  
  4         129  
10 4     4   40 use base qw( Template::Plugin );
  4         10  
  4         1329  
11              
12             sub new {
13 2     2 1 784546 my ($class, $context, @args) = @_;
14 2         22 my @cal = Calendar::Simple::calendar( @args );
15 2         1706 return bless {
16             _CONTEXT => $context,
17             rows => Template::Iterator->new( [@cal] ),
18             days => [qw( Sun Mon Tue Wed Thu Fri Sat )],
19             }, $class;
20             }
21              
22             sub rows {
23 2     2 1 708 my ($self) = shift;
24 2         9 return $self->{rows};
25             }
26              
27             sub days {
28 2     2 1 176 my ($self, $monday_starts_week) = @_;
29 2         6 my @days = @{ $self->{days} };
  2         20  
30 2 100       12 push @days, shift @days if $monday_starts_week;
31 2         14 return [@days];
32             }
33              
34             1;
35             __END__
36              
37             =head1 NAME
38              
39             Template::Plugin::Calendar::Simple - Just another HTML calendar generator.
40              
41             =head1 SYNOPSIS
42              
43             [% USE cal = Calendar.Simple %]
44              
45             <table border="1">
46             <tr>
47             [% FOREACH day = cal.days %]
48             <th>[% day %]</th>
49             [% END %]
50             </tr>
51             [% FOREACH row = cal.rows %]
52             <tr>
53             [% FOREACH col = row %]
54             <td>[% col || '&nbsp;' %]</td>
55             [% END %]
56             </tr>
57             [% END %]
58             </table>
59              
60             =head1 DESCRIPTION
61              
62             Provides calendar delimiters for a Template Toolkit template via
63             L<Calendar::Simple>. This module supplies the data, you supply the HTML.
64             Defaults to current month within the current year. Past months and years
65             can be specified within the Template constructor:
66              
67             [% USE cal = Calendar.Simple( 5, 2000 ) %]
68              
69             Can generate calendars that start with Monday instead of Sunday like so:
70              
71             [% USE cal = Calendar.Simple( 5, 2000, 1 ) %]
72             ...
73             [% FOREACH day = cal.days( 1 ) %]
74             ...
75              
76             See the unit tests for more examples.
77              
78             =head1 METHODS
79              
80             =over 4
81              
82             =item C<new()>
83              
84             Constructor. Will be called for you by the Template Toolkit engine.
85              
86             =item C<rows()>
87              
88             [% FOREACH row = cal.rows %]
89              
90             Returns a Template::Iterator which contains the calendar rows.
91             Each row, however, is simply an array.
92              
93             =item C<days()>
94              
95             [% FOREACH day = cal.days %]
96              
97             Most calendars have a header with the days - this method returns
98             an array of abbreviated day names (currently only in English). If
99             any argument is passed, then the week day starts with Monday instead
100             of Sunday.
101              
102             =back
103              
104             =head1 SEE ALSO
105              
106             =over 4
107              
108             =item * L<Template::Plugin>
109              
110             =item * L<Calendar::Simple>.
111              
112             =back
113              
114             =head1 BUGS AND LIMITATIONS
115              
116              
117             Please report any bugs or feature requests to either
118              
119             =over 4
120              
121             =item * Email: C<bug-template-plugin-calendar-simple at rt.cpan.org>
122              
123             =item * Web: L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Template-Plugin-Calendar-Simple>
124              
125             =back
126              
127             I will be notified, and then you'll automatically be notified of progress
128             on your bug as I make changes.
129              
130             =head1 GITHUB
131              
132             The Github project is L<https://github.com/jeffa/Template-Plugin-Calendar-Simple>
133              
134             =head1 SUPPORT
135              
136             You can find documentation for this module with the perldoc command.
137              
138             perldoc Template::Plugin::Calendar::Simple
139              
140             You can also look for information at:
141              
142             =over 4
143              
144             =item * RT: CPAN's request tracker (report bugs here) L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Plugin-Calendar-Simple>
145              
146             =item * AnnoCPAN: Annotated CPAN documentation L<http://annocpan.org/dist/Template-Plugin-Calendar-Simple>
147              
148             =item * CPAN Ratings L<http://cpanratings.perl.org/d/Template-Plugin-Calendar-Simple>
149              
150             =item * Search CPAN L<http://search.cpan.org/dist/Template-Plugin-Calendar-Simple>
151              
152             =back
153              
154             =head1 AUTHOR
155              
156             Jeff Anderson, C<< <jeffa at cpan.org> >>
157              
158             =head1 LICENSE AND COPYRIGHT
159              
160             Copyright 2024 Jeff Anderson.
161              
162             This program is free software; you can redistribute it and/or modify it
163             under the terms of the the Artistic License (2.0). You may obtain a
164             copy of the full license at:
165              
166             L<http://www.perlfoundation.org/artistic_license_2_0>
167              
168             Any use, modification, and distribution of the Standard or Modified
169             Versions is governed by this Artistic License. By using, modifying or
170             distributing the Package, you accept this license. Do not use, modify,
171             or distribute the Package, if you do not accept this license.
172              
173             If your Modified Version has been derived from a Modified Version made
174             by someone other than you, you are nevertheless required to ensure that
175             your Modified Version complies with the requirements of this license.
176              
177             This license does not grant you the right to use any trademark, service
178             mark, tradename, or logo of the Copyright Holder.
179              
180             This license includes the non-exclusive, worldwide, free-of-charge
181             patent license to make, have made, use, offer to sell, sell, import and
182             otherwise transfer the Package with respect to any patent claims
183             licensable by the Copyright Holder that are necessarily infringed by the
184             Package. If you institute patent litigation (including a cross-claim or
185             counterclaim) against any party alleging that the Package constitutes
186             direct or contributory patent infringement, then this Artistic License
187             to you shall terminate on the date that such litigation is filed.
188              
189             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
190             AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
191             THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
192             PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
193             YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
194             CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
195             CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
196             EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
197              
198             =cut