File Coverage

blib/lib/App/TimeClock/Daily/ConsolePrinter.pm
Criterion Covered Total %
statement 27 27 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 3 3 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1             package App::TimeClock::Daily::ConsolePrinter;
2              
3             our @ISA = qw(App::TimeClock::Daily::PrinterInterface);
4              
5 2     2   1088 use POSIX qw(strftime);
  2         4045  
  2         7  
6              
7 2     2   1751 use utf8;
  2         16  
  2         7  
8             binmode STDOUT, ':utf8';
9              
10             our $hrline = '+' . ('-' x 62) . '+' . ('-' x 7) . '+';
11              
12             =head1 NAME
13              
14             App::TimeClock::Daily::ConsolePrinter
15              
16             =head1 DESCRIPTION
17              
18             Implements the L. Will print a simple ASCII
19             format. Suitable for using in a console/terminal.
20              
21             =head1 METHODS
22              
23             =over
24              
25             =cut
26              
27             =item print_header()
28              
29             Prints a header including todays date. The header is indented to be
30             centered above the tables printed by L. Example:
31              
32             =====================================
33             Daily Report Wed Mar 14 13:39:06 2012
34             =====================================
35              
36             =cut
37             sub print_header {
38 7     7 1 7 my $self = shift;
39 7         7 my $ident = ' ' x 17;
40 7         19 $self->_print("\n");
41 7         20 $self->_print("${ident}=====================================\n");
42 7         104 $self->_print("${ident}Daily Report " . localtime() . "\n");
43 7         16 $self->_print("${ident}=====================================\n\n");
44             };
45              
46             =item print_day()
47              
48             Prints all activities for a day including a total. Is printed in a ACSII
49             table. Example:
50              
51             * Mon 2012/03/12 (08:21:16 - 16:05:31) *
52             +--------------------------------------------------------------+-------+
53             | Total Daily Hours | 7.73 |
54             +--------------------------------------------------------------+-------+
55             | Lunch | 0.57 |
56             +--------------------------------------------------------------+-------+
57             | MyProject:Estimation | 2.90 |
58             +--------------------------------------------------------------+-------+
59             | AnotherProject:BugFixing | 4.26 |
60             +--------------------------------------------------------------+-------+
61              
62             =cut
63             sub print_day {
64 11     11 1 27 my ($self, $date, $start, $end, $work, %projects) = (@_);
65 11         26 my ($year, $mon, $mday) = split(/\//, $date);
66 11         194 my $wday = substr(strftime("%a", 0, 0, 0, $mday, $mon-1, $year-1900),0,3);
67              
68 11         56 $self->_print(sprintf("* %3s %s (%s - %s) *\n", $wday, $date, $start, $end));
69 11         25 $self->_print("$hrline\n");
70 11         73 $self->_print(sprintf("| Total Daily Hours | %5.2f |\n", $work));
71 11         23 $self->_print("$hrline\n");
72              
73 11         35 foreach my $k (sort keys %projects) {
74 21         107 $self->_print(sprintf("| %-60s | %5.2f |\n",$k, $projects{$k}));
75 21         36 $self->_print("$hrline\n");
76             }
77 11         20 $self->_print("\n");
78             };
79              
80             =item print_footer()
81              
82             Prints the total number of hours worked and the daily
83             average. Example:
84              
85             TOTAL = 291.72 hours
86             PERIOD = 42 days
87             AVERAGE = 7.95 hours/day
88              
89             =cut
90             sub print_footer {
91 7     7 1 9 my ($self, $work_year_to_date, $day_count) = (@_);
92 7         34 $self->_print(sprintf("TOTAL = %.2f hours\n", $work_year_to_date));
93 7         16 $self->_print(sprintf("PERIOD = %d days\n", $day_count));
94 7 100       34 $self->_print(sprintf("AVERAGE = %.2f hours/day\n", $day_count > 0 ? $work_year_to_date / $day_count : 0));
95             };
96             1;
97              
98             =back
99              
100             =for text
101             =encoding utf-8
102             =end
103              
104             =head1 AUTHOR
105              
106             Søren Lund, C<< >>
107              
108             =head1 SEE ALSO
109              
110             L
111              
112             =head1 COPYRIGHT
113              
114             Copyright (C) 2012-2015 Søren Lund
115              
116             This file is part of App::TimeClock.
117              
118             App::TimeClock is free software: you can redistribute it and/or modify
119             it under the terms of the GNU General Public License as published by
120             the Free Software Foundation, either version 3 of the License, or
121             (at your option) any later version.
122              
123             App::TimeClock is distributed in the hope that it will be useful,
124             but WITHOUT ANY WARRANTY; without even the implied warranty of
125             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
126             GNU General Public License for more details.
127              
128             You should have received a copy of the GNU General Public License
129             along with App::TimeClock. If not, see .