line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
803
|
use strict; use warnings; |
|
1
|
|
|
1
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
52
|
|
2
|
|
|
|
|
|
|
package Devel::PerlLog; |
3
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
11
|
use Fcntl qw(:flock SEEK_END); |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
157
|
|
6
|
1
|
|
|
1
|
|
530
|
use Time::HiRes; |
|
1
|
|
|
|
|
1263
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my $log_path; |
9
|
|
|
|
|
|
|
my $log_handle; |
10
|
|
|
|
|
|
|
my %data; |
11
|
|
|
|
|
|
|
my @plugins; |
12
|
|
|
|
|
|
|
my %group = ( |
13
|
|
|
|
|
|
|
all => [qw(argv cwd pid)], |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub write_log { |
17
|
2
|
|
|
2
|
0
|
4
|
my ($text) = @_; |
18
|
2
|
50
|
|
|
|
7
|
if ($log_path ne 'STDOUT') { |
19
|
0
|
0
|
|
|
|
0
|
flock $log_handle, LOCK_EX |
20
|
|
|
|
|
|
|
or die "Cannot lock '$log_path':\n$!\n"; |
21
|
0
|
0
|
|
|
|
0
|
seek $log_handle, 0, SEEK_END |
22
|
|
|
|
|
|
|
or die "Cannot seek '$log_path':\n$!\n"; |
23
|
|
|
|
|
|
|
} |
24
|
2
|
|
|
|
|
68
|
print $log_handle $text; |
25
|
2
|
50
|
|
|
|
21
|
if ($log_path ne 'STDOUT') { |
26
|
0
|
0
|
|
|
|
0
|
flock $log_handle, LOCK_UN |
27
|
|
|
|
|
|
|
or die "Cannot unlock '$log_path':\n$!\n"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub import { |
32
|
1
|
|
|
1
|
|
9
|
my ($class, @args) = @_; |
33
|
1
|
|
|
|
|
3
|
for my $arg (@args) { |
34
|
0
|
0
|
|
|
|
0
|
if ($arg =~ m![\\\/\.]!) { |
|
|
0
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
0
|
die "Devel::PerlLog log path already set to '$log_path'" |
36
|
|
|
|
|
|
|
if $log_path; |
37
|
0
|
|
|
|
|
0
|
$log_path = $arg; |
38
|
0
|
0
|
|
|
|
0
|
open $log_handle, '>>', $log_path |
39
|
|
|
|
|
|
|
or die "Can't open '$log_path' for append:\n$!"; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
elsif ($arg =~ m!^(all)$!) { |
42
|
0
|
0
|
|
|
|
0
|
die "No support for Devel::PerlLog '$arg'" |
43
|
|
|
|
|
|
|
unless $group{$arg}; |
44
|
0
|
|
|
|
|
0
|
$class->add(@{$group{$arg}}); |
|
0
|
|
|
|
|
0
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
0
|
|
|
|
|
0
|
$class->add($arg); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
} |
50
|
1
|
|
50
|
|
|
8
|
$log_handle ||= \*STDOUT; |
51
|
1
|
|
50
|
|
|
5
|
$log_path ||= 'STDOUT'; |
52
|
1
|
|
|
|
|
1
|
for my $plugin (@plugins) { |
53
|
0
|
|
|
|
|
0
|
my $method = "do_$plugin"; |
54
|
0
|
0
|
|
|
|
0
|
die "No support for Devel::PerlLog '$plugin'" |
55
|
|
|
|
|
|
|
unless $class->can($method); |
56
|
0
|
|
|
|
|
0
|
$class->$method; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
102
|
my $time = localtime; |
59
|
1
|
|
|
|
|
9
|
write_log "# $time ($$) Perl BEGIN:\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
END { |
63
|
|
|
|
|
|
|
require YAML::XS; |
64
|
|
|
|
|
|
|
$YAML::XS::Head = 0; |
65
|
|
|
|
|
|
|
my $time = localtime; |
66
|
|
|
|
|
|
|
write_log "# $time ($$) Perl END:\n"; |
67
|
|
|
|
|
|
|
my @keys = keys %data; |
68
|
|
|
|
|
|
|
return unless @keys; |
69
|
|
|
|
|
|
|
my $dump = YAML::XS::Dump(\%data); |
70
|
|
|
|
|
|
|
$dump =~ s/\A---\s*//; |
71
|
|
|
|
|
|
|
write_log $dump; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub add { |
75
|
0
|
|
|
0
|
0
|
|
my ($class, @names) = @_; |
76
|
0
|
|
|
|
|
|
for my $name (@names) { |
77
|
0
|
|
|
|
|
|
@plugins = grep { $_ ne $name } @plugins; |
|
0
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
push @plugins, $name; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
#------------------------------------------------------------------------------ |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub do_argv { |
85
|
0
|
|
|
0
|
0
|
|
$data{argv} = join ', ', @ARGV; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub do_cwd { |
89
|
0
|
|
|
0
|
0
|
|
require Cwd; |
90
|
0
|
|
|
|
|
|
$data{cwd} = Cwd::cwd(); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub do_pid { |
94
|
0
|
|
|
0
|
0
|
|
$data{pid} = $$; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |