File Coverage

blib/lib/App/TimeClock/Daily/PrinterInterface.pm
Criterion Covered Total %
statement 19 19 100.0
branch n/a
condition 1 2 100.0
subroutine 10 10 100.0
pod 4 4 100.0
total 34 35 100.0


line stmt bran cond sub pod time code
1             package App::TimeClock::Daily::PrinterInterface;
2              
3 5     5   48824 use strict;
  5         6  
  5         111  
4 5     5   18 use warnings;
  5         6  
  5         1125  
5              
6             =head1 NAME
7              
8             App::TimeClock::Daily::PrinterInterface
9              
10             =head1 DESCRIPTION
11              
12             Interface class. All printer objects given to
13             L constructor must be derived from
14             PrinterInterface.
15              
16             =head1 SYNOPSIS
17              
18             package App::TimeClock::Daily::MyPrinter;
19             our @ISA = qw(App::TimeClock::Daily::PrinterInterface);
20             ...
21             sub print_header {
22             ...
23             }
24             sub print_day {
25             ...
26             }
27             sub print_footer {
28             ...
29             }
30              
31             =head1 METHODS
32              
33             =over
34              
35             =cut
36              
37             =item new()
38              
39             Creates a new object.
40              
41             =cut
42             sub new {
43 5     5 1 96 bless { }, shift;
44             }
45              
46             =item _print()
47              
48             Private print method that uses handle specified by L<_set_ouput_fh> or stdout by default.
49             All implementing classes should use _print to print instead of print.
50             This makes testing much easier.
51              
52             =cut
53             sub _print {
54 192     192   141 my $self = shift;
55 192         181 my $fh = $self->_get_output_fh;
56 192         129 print { $fh } @_;
  192         493  
57             }
58              
59             =item _get_output_fh()
60              
61             Get the file handle used by L<_print>.
62              
63             =cut
64             sub _get_output_fh {
65             # When testing _output will always be set, i.e. skip coverage check of right condition
66             # uncoverable condition right
67 192   50 192   303 return $_[0]->{_output} || \*STDOUT;
68             }
69              
70             =item _set_ouput_fh()
71              
72             Set the file handle used by L<_print>.
73              
74             =cut
75 12     12   15483 sub _set_output_fh { $_[0]->{_output} = $_[1] }
76              
77             =item print_header()
78              
79             Called once at the start of a report.
80              
81             =cut
82 1     1 1 30 sub print_header { shift->_must_implement; };
83              
84             =item print_day()
85              
86             Called for each day in the report.
87              
88             =cut
89 1     1 1 18 sub print_day { shift->_must_implement; };
90              
91             =item print_footer()
92              
93             Called once at the end of a report.
94              
95             =cut
96 1     1 1 16 sub print_footer { shift->_must_implement; };
97              
98             sub _must_implement {
99 3     3   21 (my $name = (caller(1))[3]) =~ s/^.*:://;
100 3         11 my ($filename, $line) = (caller(0))[1..2];
101 3         28 die "You must implement $name() method at $filename line $line";
102             }
103             1;
104              
105             =back
106              
107             =for text
108             =encoding utf-8
109             =end
110              
111             =head1 AUTHOR
112              
113             Søren Lund, C<< >>
114              
115             =head1 SEE ALSO
116              
117             L
118              
119             =head1 COPYRIGHT
120              
121             Copyright (C) 2012-2015 Søren Lund
122              
123             This file is part of App::TimeClock.
124              
125             App::TimeClock is free software: you can redistribute it and/or modify
126             it under the terms of the GNU General Public License as published by
127             the Free Software Foundation, either version 3 of the License, or
128             (at your option) any later version.
129              
130             App::TimeClock is distributed in the hope that it will be useful,
131             but WITHOUT ANY WARRANTY; without even the implied warranty of
132             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
133             GNU General Public License for more details.
134              
135             You should have received a copy of the GNU General Public License
136             along with App::TimeClock. If not, see .