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