line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Web::ChromeLogger; |
2
|
4
|
|
|
4
|
|
149439
|
use 5.008005; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
173
|
|
3
|
4
|
|
|
4
|
|
35
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
163
|
|
4
|
4
|
|
|
4
|
|
22
|
use warnings; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
285
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = "0.05"; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
4777
|
use JSON::XS qw//; |
|
4
|
|
|
|
|
36938
|
|
|
4
|
|
|
|
|
115
|
|
9
|
4
|
|
|
4
|
|
4129
|
use MIME::Base64 qw//; |
|
4
|
|
|
|
|
3239
|
|
|
4
|
|
|
|
|
3082
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
3
|
|
|
3
|
1
|
40
|
my $class = shift; |
13
|
3
|
50
|
|
|
|
27
|
my %args = @_==1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
14
|
3
|
|
|
|
|
15
|
my $self = bless { |
15
|
|
|
|
|
|
|
%args |
16
|
|
|
|
|
|
|
}, $class; |
17
|
|
|
|
|
|
|
# allow_unknown: Should not throw an exception if when it encounters values it cannot represent in JSON. |
18
|
3
|
|
33
|
|
|
95
|
$self->{'json_encoder'} ||= JSON::XS->new()->ascii(1)->convert_blessed->allow_unknown; |
19
|
3
|
|
|
|
|
12
|
$self->{'logs'} = []; |
20
|
3
|
|
|
|
|
13
|
return $self; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
3
|
|
|
3
|
1
|
92
|
sub json_encoder { $_[0]->{json_encoder} } |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub group { |
26
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
27
|
1
|
|
|
|
|
3
|
$self->push_log('group', @_); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub groupf { |
31
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
32
|
1
|
|
|
|
|
2
|
my $format = shift; |
33
|
1
|
|
|
|
|
6
|
$self->group(sprintf $format, @_); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub group_end { |
37
|
3
|
|
|
3
|
1
|
9
|
my $self = shift; |
38
|
3
|
|
|
|
|
8
|
$self->push_log('groupEnd', @_); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub group_endf { |
42
|
2
|
|
|
2
|
1
|
10
|
my $self = shift; |
43
|
2
|
|
|
|
|
4
|
my $format = shift; |
44
|
2
|
|
|
|
|
9
|
$self->group_end(sprintf $format, @_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub group_collapsed { |
48
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
49
|
2
|
|
|
|
|
8
|
$self->push_log('groupCollapsed', @_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub group_collapsedf { |
53
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
54
|
1
|
|
|
|
|
6
|
my $format = shift; |
55
|
1
|
|
|
|
|
16
|
$self->group_collapsed(sprintf $format, @_); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub info { |
59
|
5
|
|
|
5
|
1
|
26
|
my $self = shift; |
60
|
5
|
|
|
|
|
19
|
$self->push_log('info', @_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub infof { |
64
|
2
|
|
|
2
|
1
|
12
|
my $self = shift; |
65
|
2
|
|
|
|
|
4
|
my $format = shift; |
66
|
2
|
|
|
|
|
11
|
$self->info(sprintf $format, @_); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub warn { |
70
|
2
|
|
|
2
|
1
|
7
|
my $self = shift; |
71
|
2
|
|
|
|
|
7
|
$self->push_log('warn', @_); |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub warnf { |
75
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
76
|
1
|
|
|
|
|
2
|
my $format = shift; |
77
|
1
|
|
|
|
|
6
|
$self->warn(sprintf $format, @_); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub error { |
81
|
2
|
|
|
2
|
1
|
8
|
my $self = shift; |
82
|
2
|
|
|
|
|
7
|
$self->push_log('error', @_); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub errorf { |
86
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
87
|
1
|
|
|
|
|
3
|
my $format = shift; |
88
|
1
|
|
|
|
|
5
|
$self->error(sprintf $format, @_); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# User can overwrite this method in child class. |
92
|
|
|
|
|
|
|
sub to_json { |
93
|
0
|
|
|
0
|
0
|
0
|
my ($self, $stuff) = @_; |
94
|
0
|
|
|
|
|
0
|
"$stuff" |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub encode { |
98
|
3
|
|
|
3
|
0
|
8
|
my ($self, $rows) = @_; |
99
|
|
|
|
|
|
|
|
100
|
4
|
|
|
4
|
|
30
|
no warnings 'once'; |
|
4
|
|
|
|
|
14
|
|
|
4
|
|
|
|
|
1929
|
|
101
|
3
|
|
|
0
|
|
18
|
local *UNIVERSAL::TO_JSON = sub { $self->to_json(@_) }; |
|
0
|
|
|
|
|
0
|
|
102
|
3
|
|
|
|
|
13
|
my $json_data = $self->json_encoder->encode( |
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
"version" => "0.2", |
105
|
|
|
|
|
|
|
"columns" => [ "log", "backtrace", "type" ], |
106
|
|
|
|
|
|
|
"rows" => $rows, |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
); |
109
|
3
|
|
|
|
|
42
|
my $mime_data = MIME::Base64::encode_base64($json_data); |
110
|
3
|
|
|
|
|
29
|
$mime_data =~ s/\n/''/g; |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
25
|
return $mime_data; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub wrap_by_group { |
116
|
2
|
|
|
2
|
1
|
9
|
my ($self, $title) = @_; |
117
|
2
|
|
|
|
|
13
|
$self->unshift_log('group', $title); |
118
|
2
|
|
|
|
|
6
|
$self->push_log('groupEnd', $title); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub wrap_by_groupf { |
122
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
123
|
1
|
|
|
|
|
3
|
my $format = shift; |
124
|
1
|
|
|
|
|
5
|
$self->wrap_by_group(sprintf $format, @_); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub push_log { |
128
|
17
|
|
|
17
|
0
|
28
|
my $self = shift; |
129
|
17
|
|
|
|
|
22
|
push @{ $self->{logs} }, [ [ $_[1] ], $_[2], $_[0] ]; |
|
17
|
|
|
|
|
97
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub unshift_log { |
133
|
2
|
|
|
2
|
0
|
19
|
my $self = shift; |
134
|
2
|
|
|
|
|
4
|
unshift @{ $self->{logs} }, [ [ $_[1] ], $_[2], $_[0] ]; |
|
2
|
|
|
|
|
14
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub finalize { |
138
|
3
|
|
|
3
|
1
|
17
|
my ($self) = @_; |
139
|
3
|
|
|
|
|
13
|
$self->encode($self->{logs}); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
1; |
143
|
|
|
|
|
|
|
__END__ |