line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OPM::Installer::Logger; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: A simple logger for OPM::Installer |
4
|
|
|
|
|
|
|
|
5
|
13
|
|
|
13
|
|
262328
|
use strict; |
|
13
|
|
|
|
|
49
|
|
|
13
|
|
|
|
|
319
|
|
6
|
13
|
|
|
13
|
|
58
|
use warnings; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
480
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.0'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
1383
|
use Moo; |
|
13
|
|
|
|
|
28071
|
|
|
13
|
|
|
|
|
56
|
|
11
|
13
|
|
|
13
|
|
7277
|
use IO::All; |
|
13
|
|
|
|
|
34743
|
|
|
13
|
|
|
|
|
70
|
|
12
|
13
|
|
|
13
|
|
2550
|
use File::Temp; |
|
13
|
|
|
|
|
44559
|
|
|
13
|
|
|
|
|
777
|
|
13
|
13
|
|
|
13
|
|
5696
|
use Time::Piece; |
|
13
|
|
|
|
|
103514
|
|
|
13
|
|
|
|
|
66
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $file = File::Temp->new->filename; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has log => ( is => 'ro', lazy => 1, default => sub { $file } ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
for my $level (qw/notice info debug warn error/) { |
20
|
13
|
|
|
13
|
|
1286
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
3770
|
|
21
|
|
|
|
|
|
|
*{"OPM::Installer::Logger::$level"} = sub { |
22
|
12
|
|
|
12
|
|
23522
|
shift->print( $level, @_ ); |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub print { |
27
|
12
|
|
|
12
|
1
|
57
|
my ($self, $tag, %attr) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $attrs = join " ", map{ |
30
|
12
|
|
50
|
|
|
64
|
my $escaped = $attr{$_} // ''; |
|
32
|
|
|
|
|
87
|
|
31
|
32
|
|
|
|
|
57
|
$escaped =~ s{\\}{\\\\}g; |
32
|
32
|
|
|
|
|
43
|
$escaped =~ s{"}{\\"}g; |
33
|
|
|
|
|
|
|
|
34
|
32
|
|
|
|
|
113
|
sprintf '%s="%s"', $_, $escaped |
35
|
|
|
|
|
|
|
}sort keys %attr; |
36
|
|
|
|
|
|
|
|
37
|
12
|
|
|
|
|
45
|
my $date = localtime; |
38
|
12
|
|
|
|
|
707
|
my $message = sprintf "[%s] [%s %s] %s \n", uc $tag, $date->ymd, $date->hms, $attrs; |
39
|
12
|
|
|
|
|
512
|
$message >> io $self->log; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub BUILD { |
43
|
15
|
|
|
15
|
1
|
19694
|
my ($self, $param) = @_; |
44
|
|
|
|
|
|
|
|
45
|
15
|
100
|
|
|
|
55
|
if ( $param->{path} ) { |
46
|
1
|
|
|
|
|
3
|
$file = $param->{path}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
15
|
|
|
|
|
60
|
my $date = localtime; |
50
|
15
|
|
|
|
|
1127
|
my $message = sprintf "[DEBUG] [%s %s] Start installation...\n", $date->ymd, $date->hms; |
51
|
|
|
|
|
|
|
|
52
|
15
|
|
|
|
|
1095
|
$message > io $self->log |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |