Renderer/Text.pm

filter: Statementstmt 24.2% 24 / 99 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 36.3% 4 / 11 Podpod 85.7% 6 / 7 totaltotal 24.6% 34 / 138 CC 14 SCAR 33.4
CC
14
Cov
20%
get_dates
72.0
BUILD
12.0
get_day_header
12.0
CRAP 28.3
« Renderer/SVG.pm ↑ Summary Renderer/Util.pm »
1 package Calendar::Plugin::Renderer::Text;
2  
3 3 $Calendar::Plugin::Renderer::Text::VERSION = '0.14';
4 3 $Calendar::Plugin::Renderer::Text::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 Calendar::Plugin::Renderer::Text - Interface to render calendar in text format.
9  
10 =head1 VERSION
11  
12 Version 0.14
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  
19 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 has 'start_index' => (is => 'ro', required => 1);
23 3 has 'month_name' => (is => 'ro', required => 1);
24 3 has 'days' => (is => 'ro', required => 1);
25 3 has 'year' => (is => 'ro', required => 1);
26 3 has 'day_names' => (is => 'ro', required => 1);
27  
28 3 has 'max_days_name' => (is => 'rw');
29 3 has 'line_size' => (is => 'rw');
30 3 has 'f' => (is => 'rw');
31 3 has 's' => (is => 'rw');
32 3 has 'month_head' => (is => 'rw');
33  
34 =head1 DESCRIPTION
35  
36 Interface to render calendar in text format.
37  
38 =head1 CONSTRUCTOR
39  
40 It expects one parameter as a hash ref with keys mentioned in the below table.
41  
42 +-------------+-------------------------------------------------------------+
43 | Key | Description |
44 +-------------+-------------------------------------------------------------+
45 | start_index | Index (0-6) for the first day of the month, 0 for Sunday. |
46 | month_name | Name of the given month. |
47 | days | Total days count for the given month. |
48 | year | Given year. |
49 | day_names | Ref to a list of day name starting with Sunday. |
50 +-------------+-------------------------------------------------------------+
51  
52 =cut
53  
54 sub BUILD {
55 0 ▶ my ($self) = @_;
Subroutine BUILD: not called CC=3 SCAR=24.8
Pod undocumented
56  
57 0 my $day_names = $self->day_names;
58 0 my $month_name = $self->month_name;
59 0 my $year = $self->year;
60  
61 0 my $max_days_name = 0;
62 0 foreach my $day_name (@$day_names) {
63 0 ▶ if ($max_days_name < length($day_name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($max_days_name < length $day_name) 0 0 0
64 0 $max_days_name = length($day_name);
65 }
66 }
67  
68 0 my $line_size = (7 * ($max_days_name + 2)) + 8;
69 0 my $month_head = sprintf("%s [%d BE]", $month_name, $year);
70 0 my $h = int($line_size/2);
71 0 my $m = int(length($month_head)/2);
72 0 my $f = $h - $m;
73 0 my $s = $line_size - ($f + length($month_head));
74  
75 0 $self->max_days_name($max_days_name);
76 0 $self->line_size($line_size);
77 0 $self->month_head($month_head);
78 0 $self->f($f);
79 0 $self->s($s);
80 }
81  
82 =head1 METHODS
83  
84 =head2 get_day_header()
85  
86 =cut
87  
88 sub get_day_header {
89 0 ▶ my ($self) = @_;
Subroutine get_day_header: not called CC=3 SCAR=24.8
Pod documented
90  
91 0 my $max_length_day_name = $self->max_days_name;
92 0 my $day_names = $self->day_names;
93 0 my $line = '<blue><bold>|</bold></blue>';
94 0 my $i = 1;
95 0 foreach (@$day_names) {
96 0 my $x = length($_);
97 0 my $y = $max_length_day_name - $x;
98 0 my $z = $y + 1;
99 0 ▶ if ($i == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 1) { } 0 0 0
100 0 $line .= ((' ')x$z). "<yellow><bold>$_</bold></yellow>";
101 0 $i++;
102 }
103 else {
104 0 $line .= " <blue><bold>|</bold></blue>".((' ')x$z)."<yellow><bold>$_</bold></yellow>";
105 }
106  
107 }
108 0 $line .= " <blue><bold>|</bold></blue>";
109  
110 0 return $line;
111 }
112  
113 =head2 get_month_header()
114  
115 =cut
116  
117 sub get_month_header {
118 0 ▶ my ($self) = @_;
Subroutine get_month_header: not called CC=1 SCAR=6.9
Pod documented
119  
120 0 my $f = $self->f;
121 0 my $s = $self->s;
122 0 my $h = $self->month_head;
123  
124 0 return '<blue><bold>|</bold></blue>'.
125 (' ')x($f-1).
126 '<yellow><bold>'.
127 $h.
128 '</bold></yellow>'.
129 (' ')x($s-1).
130 '<blue><bold>|</bold></blue>';
131 }
132  
133 =head2 get_dashed_line()
134  
135 =cut
136  
137 sub get_dashed_line {
138 0 ▶ my ($self) = @_;
Subroutine get_dashed_line: not called CC=1 SCAR=6.9
Pod documented
139  
140 0 my $line_size = $self->line_size;
141 0 return '<blue><bold>+'.('-')x($line_size-2).'+</bold></blue>';
142 }
143  
144 =head2 get_blocked_line()
145  
146 =cut
147  
148 sub get_blocked_line {
149 0 ▶ my ($self) = @_;
Subroutine get_blocked_line: not called CC=2 SCAR=17.9
Pod documented
150  
151 0 my $max_length_day_name = $self->max_days_name;
152 0 my $line = '<blue><bold>+';
153 0 foreach (1..7) {
154 0 $line .= ('-')x($max_length_day_name+2).'+';
155 }
156  
157 0 $line .= '</bold></blue>';
158  
159 0 return $line;
160 }
161  
162 =head2 get_empty_space()
163  
164 =cut
165  
166 sub get_empty_space {
167 0 ▶ my ($self) = @_;
Subroutine get_empty_space: not called CC=2 SCAR=17.9
Pod documented
168  
169 0 my $max_length_day_name = $self->max_days_name;
170 0 my $start_index = $self->start_index;
171 0 my $line = '';
172 0 ▶ if ($start_index % 7 != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_index % 7 != 0) 0 0 0
173 0 $line .= '<blue><bold>|</bold></blue>'.(' ')x($max_length_day_name+2);
174 0 map { $line .= ' 'x($max_length_day_name+3) } (2..($start_index %= 7));
175 }
176  
177 0 return $line;
178 }
179  
180 =head2 get_dates()
181  
182 =cut
183  
184 sub get_dates {
185 0 ▶ my ($self) = @_;
Subroutine get_dates: not called CC=8 SCAR=42.8
Pod documented
186  
187 0 my $max_length_day_name = $self->max_days_name;
188 0 my $start_index = $self->start_index;
189 0 my $days = $self->days;
190 0 my $line = '';
191 0 my $blocked_line = $self->get_blocked_line;
192 0 foreach (1 .. $days) {
193 0 $line .= sprintf("<blue><bold>|</bold></blue><cyan><bold>%".($max_length_day_name+1)."s </bold></cyan>", $_);
194 0 ▶ if ($_ != $days) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ != $days) { } 0 0 0
elsif ($_ == $days) { } 0 0 0
195 0 ▶ $line .= "<blue><bold>|</bold></blue>\n".$blocked_line."\n" unless (($start_index + $_) % 7);
Branch: 1 branch
BranchTrueFalseTotal
unless ($start_index + $_) % 7 0 0 0
196 }
197 elsif ($_ == $days) {
198 0 my $x = 7 - (($start_index + $_) % 7);
199 0 ▶ if (($x >= 2) && ($x != 7)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($x >= 2 and $x != 7) { } 0 0 0
elsif ($x != 7) { } 0 0 0
Condition0%0/3
$x >= 2 and $x != 7
!ll&&!rl&&r
000
MC/DC0%0/2
$x >= 2 and $x != 7
$x >= 2 $x != 7
Truth table0%0/3
A and B
A= $x >= 2B= $x != 7
ABresult
0X0
100
111
200 0 $line .= '<blue><bold>|</bold></blue>'. (' 'x($max_length_day_name+2));
201 0 map { $line .= ' 'x($max_length_day_name+3) } (1..$x-1);
202 }
203 elsif ($x != 7) {
204 0 $line .= '<blue><bold>|</bold></blue>'.' 'x($max_length_day_name+2);
205 }
206 }
207 }
208  
209 0 return sprintf("%s<blue><bold>|</bold></blue>\n%s\n", $line, $blocked_line);
210 }
211  
212  
213 =head1 AUTHOR
214  
215 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
216  
217 =head1 REPOSITORY
218  
219 L<https://github.com/manwar/Calendar-Plugin-Renderer>
220  
221 =head1 BUGS
222  
223 Please report any bugs / feature requests to C<bug-calendar-plugin-renderer at rt.cpan.org>,
224 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Calendar-Plugin-Renderer>.
225 I will be notified, and then you'll automatically be notified of progress on your
226 bug as I make changes.
227  
228 =head1 SUPPORT
229  
230 You can find documentation for this module with the perldoc command.
231  
232 perldoc Calendar::Plugin::Renderer::Text
233  
234 You can also look for information at:
235  
236 =over 4
237  
238 =item * RT: CPAN's request tracker
239  
240 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Calendar-Plugin-Renderer>
241  
242 =item * AnnoCPAN: Annotated CPAN documentation
243  
244 L<http://annocpan.org/dist/Calendar-Plugin-Renderer>
245  
246 =item * CPAN Ratings
247  
248 L<http://cpanratings.perl.org/d/Calendar-Plugin-Renderer>
249  
250 =item * Search CPAN
251  
252 L<http://search.cpan.org/dist/Calendar-Plugin-Renderer/>
253  
254 =back
255  
256 =head1 LICENSE AND COPYRIGHT
257  
258 Copyright (C) 2015 - 2016 Mohammad S Anwar.
259  
260 This program is free software; you can redistribute it and / or modify it under
261 the terms of the the Artistic License (2.0). You may obtain a copy of the full
262 license at:
263  
264 L<http://www.perlfoundation.org/artistic_license_2_0>
265  
266 Any use, modification, and distribution of the Standard or Modified Versions is
267 governed by this Artistic License.By using, modifying or distributing the Package,
268 you accept this license. Do not use, modify, or distribute the Package, if you do
269 not accept this license.
270  
271 If your Modified Version has been derived from a Modified Version made by someone
272 other than you,you are nevertheless required to ensure that your Modified Version
273 complies with the requirements of this license.
274  
275 This license does not grant you the right to use any trademark, service mark,
276 tradename, or logo of the Copyright Holder.
277  
278 This license includes the non-exclusive, worldwide, free-of-charge patent license
279 to make, have made, use, offer to sell, sell, import and otherwise transfer the
280 Package with respect to any patent claims licensable by the Copyright Holder that
281 are necessarily infringed by the Package. If you institute patent litigation
282 (including a cross-claim or counterclaim) against any party alleging that the
283 Package constitutes direct or contributory patent infringement,then this Artistic
284 License to you shall terminate on the date that such litigation is filed.
285  
286 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
287 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
288 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
289 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
290 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
291 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
292 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
293  
294 =cut
295  
296 3 1; # End of Calendar::Plugin::Renderer::Text
« Renderer/SVG.pm ↑ Summary Renderer/Util.pm »