File Coverage

blib/lib/App/RunCron/Reporter/File.pm
Criterion Covered Total %
statement 39 39 100.0
branch 5 6 83.3
condition n/a
subroutine 10 10 100.0
pod 1 2 50.0
total 55 57 96.4


line stmt bran cond sub pod time code
1             package App::RunCron::Reporter::File;
2 3     3   1107 use strict;
  3         7  
  3         101  
3 3     3   11 use warnings;
  3         4  
  3         70  
4 3     3   12 use utf8;
  3         2  
  3         17  
5              
6 3     3   69 use File::Path qw/mkpath/;
  3         4  
  3         298  
7 3     3   15 use File::Basename qw/dirname/;
  3         3  
  3         188  
8 3     3   2088 use Time::Piece;
  3         29265  
  3         19  
9 3     3   259 use parent 'App::RunCron::Reporter';
  3         5  
  3         28  
10             use Class::Accessor::Lite (
11 3         32 ro => [qw/file/],
12 3     3   222 );
  3         6  
13              
14             sub new {
15 4     4 1 7 my $class = shift;
16 4 100       17 my %args = @_ == 1 ? %{$_[0]} : @_;
  3         15  
17 4         18 my $self = bless \%args, $class;
18              
19 4 100       15 defined $self->file or die 'file is required option';
20 3         67 $self;
21             }
22              
23             sub run {
24 2     2 0 3 my ($self, $runner) = @_;
25              
26 2         5 my $file = $self->file;
27 2         16 my $now = localtime;
28 2         159 $file = $now->strftime($file);
29 2         244 my $dir = dirname($file);
30 2         92 mkpath $dir;
31              
32 2 50       141 open my $fh, '>>', $file or die $!;
33 2         12 print $fh '-'x78, "\n" . $runner->report;
34 2         96 close $fh;
35             }
36              
37             1;