line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Plugin::Stringify; |
2
|
|
|
|
|
|
|
# ABSTRACT: Custom argument stringification plugin for log adapters |
3
|
|
|
|
|
|
|
$Log::Any::Plugin::Stringify::VERSION = '0.011'; |
4
|
2
|
|
|
2
|
|
1405
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
|
|
91
|
use Log::Any::Plugin::Util qw( |
8
|
|
|
|
|
|
|
all_logging_methods get_old_method set_new_method |
9
|
2
|
|
|
2
|
|
8
|
); |
|
2
|
|
|
|
|
4
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
517
|
use Data::Dumper; |
|
2
|
|
|
|
|
5559
|
|
|
2
|
|
|
|
|
460
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $separator; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub install { |
17
|
3
|
|
|
3
|
1
|
7
|
my ($class, $adapter_class, %args) = @_; |
18
|
|
|
|
|
|
|
|
19
|
3
|
100
|
|
|
|
9
|
$separator = defined $args{separator} ? $args{separator} : ''; |
20
|
3
|
|
100
|
|
|
15
|
my $stringifier = $args{stringifier} || \&default_stringifier; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Inject the stringifier into the existing logging methods |
23
|
|
|
|
|
|
|
# |
24
|
3
|
|
|
|
|
10
|
for my $method_name ( all_logging_methods() ) { |
25
|
57
|
|
|
|
|
121
|
my $old_method = get_old_method($adapter_class, $method_name); |
26
|
|
|
|
|
|
|
set_new_method($adapter_class, $method_name, sub { |
27
|
11
|
|
|
11
|
|
3555
|
my $self = shift; |
28
|
11
|
|
|
|
|
25
|
$self->$old_method($stringifier->(@_)); |
29
|
57
|
|
|
|
|
194
|
}); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub default_stringifier { |
34
|
10
|
|
|
10
|
1
|
18
|
my @args = @_; |
35
|
|
|
|
|
|
|
|
36
|
10
|
|
|
|
|
18
|
local $Data::Dumper::Indent = 0; |
37
|
10
|
|
|
|
|
14
|
local $Data::Dumper::Pair = '='; |
38
|
10
|
|
|
|
|
11
|
local $Data::Dumper::Quotekeys = 0; |
39
|
10
|
|
|
|
|
13
|
local $Data::Dumper::Sortkeys = 1; |
40
|
10
|
|
|
|
|
10
|
local $Data::Dumper::Terse = 1; |
41
|
|
|
|
|
|
|
|
42
|
10
|
100
|
|
|
|
16
|
return join($separator, map { ref $_ ? Dumper($_) : $_ } @args); |
|
23
|
|
|
|
|
121
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |