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   99694 use 5.008001;
  15         46  
3 15     15   75 use strict;
  15         30  
  15         299  
4 15     15   64 use warnings;
  15         31  
  15         330  
5              
6 15     15   61 use Path::Tiny qw/path/;
  15         19  
  15         579  
7 15     15   89 use IO::Handle;
  15         31  
  15         2295  
8              
9             sub new {
10 24     24 0 3928 my ( $class, %opt ) = @_;
11              
12 24         146 $opt{file} = path($opt{res_file});
13 23         1948 bless \%opt, $class;
14             }
15              
16             sub output {
17 362     362 0 1570 my ($self, $program_name, $metric_name, $metric) = @_;
18              
19             my $msg = join ",", $self->{now}->datetime, $self->{now}->epoch,
20 362         1391 $program_name, $metric_name, $metric;
21              
22 362 100       13123 if ($self->{dry_run}) {
23 145         1255 print "(dry_run) file write: $msg\n";
24 145         653 return;
25             }
26              
27 217         812 $self->{file}->append("$msg\n");
28             }
29              
30             1;
31             __END__