File Coverage

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


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