File Coverage

blib/lib/Linux/GetPidstat/Writer/File.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 7 7 100.0
pod 0 2 0.0
total 32 34 94.1


line stmt bran cond sub pod time code
1             package Linux::GetPidstat::Writer::File;
2 15     15   77813 use 5.008001;
  15         33  
3 15     15   62 use strict;
  15         30  
  15         306  
4 15     15   61 use warnings;
  15         29  
  15         324  
5              
6 15     15   64 use Path::Tiny qw/path/;
  15         29  
  15         566  
7 15     15   77 use IO::Handle;
  15         18  
  15         2427  
8              
9             sub new {
10 24     24 0 3894 my ( $class, %opt ) = @_;
11              
12 24         195 $opt{file} = path($opt{res_file});
13 23         1588 bless \%opt, $class;
14             }
15              
16             sub output {
17 362     362 0 1868 my ($self, $program_name, $metric_name, $metric) = @_;
18              
19             my $msg = join ",", $self->{now}->datetime, $self->{now}->epoch,
20 362         1291 $program_name, $metric_name, $metric;
21              
22 362 100       14080 if ($self->{dry_run}) {
23 145         1317 print "(dry_run) file write: $msg\n";
24 145         671 return;
25             }
26              
27 217         998 $self->{file}->append("$msg\n");
28             }
29              
30             1;
31             __END__