cpm/Logger/File.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 81 CC 6 SCAR 16.4
CC
6
Cov
0%
new
12.0
symlink_to
6.0
prefix
6.0
CRAP 5.2
1 package App::cpm::Logger::File;
2 use v5.24;
3 use warnings;
4 use experimental qw(lexical_subs signatures);
5  
6 use App::cpm::Util 'WIN32';
7 use File::Temp ();
8 use POSIX ();
9  
10 sub new ($class, $file = undef) {
11 my $fh;
12 if (WIN32) {
13 require IO::File;
14 $file ||= File::Temp::tmpnam();
15 } elsif ($file) {
16 open $fh, ">>:unix", $file or die "$file: $!";
17 } else {
18 ($fh, $file) = File::Temp::tempfile(UNLINK => 1);
19 }
20 bless {
21 context => '',
22 fh => $fh,
23 file => $file,
24 pid => '',
25 }, $class;
26 }
27  
28 sub symlink_to ($self, $dest) {
29 unlink $dest;
30 if (!eval { symlink $self->file, $dest }) {
31 $self->{file} = $dest;
32 }
33 }
34  
35 sub file ($self) { $self->{file} }
36  
37 sub prefix ($self) {
38 my $pid = $self->{pid} || $$;
39 $self->{context} ? "$pid,$self->{context}" : $pid;
40 }
41  
42 sub log ($self, @line) {
43 my $now = POSIX::strftime('%Y-%m-%dT%H:%M:%S', localtime);
44 my $prefix = $self->prefix;
45 local $self->{fh} = IO::File->new($self->{file}, 'a') if WIN32;
46 for my $line (@line) {
47 chomp $line;
48 print { $self->{fh} } "$now,$prefix| $_\n" for split /\n/, $line;
49 }
50 }
51  
52 1;