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
|
|
266869
|
use strict; |
|
13
|
|
|
|
|
50
|
|
|
13
|
|
|
|
|
320
|
|
6
|
13
|
|
|
13
|
|
57
|
use warnings; |
|
13
|
|
|
|
|
21
|
|
|
13
|
|
|
|
|
480
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0.1'; # VERSION |
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
1390
|
use Moo; |
|
13
|
|
|
|
|
28770
|
|
|
13
|
|
|
|
|
54
|
|
11
|
13
|
|
|
13
|
|
7575
|
use IO::All; |
|
13
|
|
|
|
|
35974
|
|
|
13
|
|
|
|
|
72
|
|
12
|
13
|
|
|
13
|
|
2654
|
use File::Temp; |
|
13
|
|
|
|
|
45337
|
|
|
13
|
|
|
|
|
782
|
|
13
|
13
|
|
|
13
|
|
5722
|
use Time::Piece; |
|
13
|
|
|
|
|
104168
|
|
|
13
|
|
|
|
|
65
|
|
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
|
|
1327
|
no strict 'refs'; ## no critic (ProhibitNoStrict) |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
3936
|
|
21
|
|
|
|
|
|
|
*{"OPM::Installer::Logger::$level"} = sub { |
22
|
12
|
|
|
12
|
|
24481
|
shift->print( $level, @_ ); |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub print { |
27
|
12
|
|
|
12
|
1
|
69
|
my ($self, $tag, %attr) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $attrs = join " ", map{ |
30
|
12
|
|
50
|
|
|
87
|
my $escaped = $attr{$_} // ''; |
|
32
|
|
|
|
|
91
|
|
31
|
32
|
|
|
|
|
63
|
$escaped =~ s{\\}{\\\\}g; |
32
|
32
|
|
|
|
|
49
|
$escaped =~ s{"}{\\"}g; |
33
|
|
|
|
|
|
|
|
34
|
32
|
|
|
|
|
123
|
sprintf '%s="%s"', $_, $escaped |
35
|
|
|
|
|
|
|
}sort keys %attr; |
36
|
|
|
|
|
|
|
|
37
|
12
|
|
|
|
|
56
|
my $date = localtime; |
38
|
12
|
|
|
|
|
865
|
my $message = sprintf "[%s] [%s %s] %s \n", uc $tag, $date->ymd, $date->hms, $attrs; |
39
|
12
|
|
|
|
|
569
|
$message >> io $self->log; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub BUILD { |
43
|
15
|
|
|
15
|
1
|
20253
|
my ($self, $param) = @_; |
44
|
|
|
|
|
|
|
|
45
|
15
|
100
|
|
|
|
65
|
if ( $param->{path} ) { |
46
|
1
|
|
|
|
|
3
|
$file = $param->{path}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
15
|
|
|
|
|
77
|
my $date = localtime; |
50
|
15
|
|
|
|
|
1362
|
my $message = sprintf "[DEBUG] [%s %s] Start installation...\n", $date->ymd, $date->hms; |
51
|
|
|
|
|
|
|
|
52
|
15
|
|
|
|
|
1162
|
$message > io $self->log |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
__END__ |