line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Any::Plugin::Format; |
2
|
|
|
|
|
|
|
# ABSTRACT: Add a formatting subroutine to your Log::Any adapter |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
11406
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
7
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
5
|
use Log::Any::Adapter::Util qw( log_level_aliases logging_methods ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
10
|
1
|
|
|
1
|
|
452
|
use Class::Method::Modifiers qw( install_modifier ); |
|
1
|
|
|
|
|
1054
|
|
|
1
|
|
|
|
|
241
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub install { |
13
|
1
|
|
|
1
|
0
|
39
|
my ($class, $adapter_class, %args) = @_; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
0
|
|
10
|
my $formatter = sub { join ' ', @_ }; |
|
0
|
|
|
|
|
0
|
|
16
|
|
|
|
|
|
|
$formatter = $args{formatter} |
17
|
1
|
50
|
33
|
|
|
8
|
if defined $args{formatter} and ref $args{formatter} eq 'CODE'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# Create format attribute if it doesn't exist |
20
|
1
|
50
|
|
|
|
11
|
unless ($adapter_class->can('format')) { |
21
|
|
|
|
|
|
|
install_modifier( $adapter_class, 'fresh', format => sub { |
22
|
4
|
|
|
4
|
|
574
|
my ($self, $sub) = @_; |
23
|
|
|
|
|
|
|
|
24
|
4
|
100
|
|
|
|
15
|
return $formatter unless defined $sub; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
2
|
$formatter = $sub; |
27
|
1
|
|
|
|
|
5
|
return $self; |
28
|
1
|
|
|
|
|
5
|
}); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
|
|
139
|
my $aliases = { log_level_aliases() }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Format input parameters for logging methods |
34
|
1
|
|
|
|
|
8
|
for my $method ( logging_methods() ) { |
35
|
|
|
|
|
|
|
install_modifier( $adapter_class, 'around', $method => sub { |
36
|
3
|
|
|
3
|
|
1294
|
my $orig = shift; |
37
|
3
|
|
|
|
|
6
|
my $self = shift; |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
44
|
my @new = $self->format->(@_); |
40
|
3
|
|
|
|
|
23
|
return $self->$orig( @new ); |
41
|
9
|
|
|
|
|
1777
|
}); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Make aliases call their counterparts |
45
|
1
|
|
|
|
|
204
|
for my $alias ( keys %{$aliases} ) { |
|
1
|
|
|
|
|
4
|
|
46
|
|
|
|
|
|
|
install_modifier( $adapter_class, 'around', $alias => sub { |
47
|
0
|
|
|
0
|
|
|
my $orig = shift; |
48
|
0
|
|
|
|
|
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $method = $aliases->{$alias}; |
51
|
0
|
|
|
|
|
|
return $self->$method(@_); |
52
|
5
|
|
|
|
|
816
|
}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
1; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
__END__ |