Installer/Logger.pm

filter: Statementstmt 100% 45 / 45 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 11 / 11 Podpod 100% 2 / 2 totaltotal 96.8% 61 / 63 CC 3 SCAR 2.7
CC
3
Cov
98%
print
2.0
BUILD
2.0
BEGIN
1.0
CRAP 1.3
« Installer/Utils/Test.pm ↑ Summary
1 package OPM::Installer::Logger;
2  
3 # ABSTRACT: A simple logger for OPM::Installer
4  
5 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 13 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 13 our $VERSION = '1.0.1'; # VERSION
9  
10 13 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 13 ▶use IO::All;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 my $file = File::Temp->new->filename;
16  
17 15 ▶has log => ( is => 'ro', lazy => 1, default => sub { $file } );
Subroutine __ANON__: called CC=1 SCAR=0.0
18  
19 13 for my $level (qw/notice info debug warn error/) {
20 13 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
21 65 ▶ *{"OPM::Installer::Logger::$level"} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
22 12 shift->print( $level, @_ );
23 65 };
24 }
25  
26 12 ▶sub print {
Subroutine print: called CC=2 SCAR=6.9
Pod documented
27 12 my ($self, $tag, %attr) = @_;
28  
29 my $attrs = join " ", map{
30 12 ▶ my $escaped = $attr{$_} // '';
Condition50%1/2
$attr{$_} // ""
l!l
320
MC/DC0%0/1
$attr{$_} // ""
$attr{$_}
Truth table50%1/2
A
A= $attr{$_}
Aresult
11
00
31 32 $escaped =~ s{\\}{\\\\}g;
32 32 $escaped =~ s{"}{\\"}g;
33  
34 32 sprintf '%s="%s"', $_, $escaped
35 }sort keys %attr;
36  
37 12 my $date = localtime;
38 12 my $message = sprintf "[%s] [%s %s] %s \n", uc $tag, $date->ymd, $date->hms, $attrs;
39 12 $message >> io $self->log;
40 }
41  
42 15 ▶sub BUILD {
Subroutine BUILD: called CC=2 SCAR=6.9
Pod documented
43 15 my ($self, $param) = @_;
44  
45 15 ▶ if ( $param->{path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($param->{"path"}) 1 14 15
46 1 $file = $param->{path};
47 }
48  
49 15 my $date = localtime;
50 15 my $message = sprintf "[DEBUG] [%s %s] Start installation...\n", $date->ymd, $date->hms;
51  
52 15 $message > io $self->log
53 }
54
55 13 1;
56  
57 __END__
« Installer/Utils/Test.pm ↑ Summary