line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::ger::Format::Sprintfn; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-03-11'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'Log-ger-Format-Sprintfn'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
68376
|
use strict; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
25
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
375
|
use Text::sprintfn; |
|
1
|
|
|
|
|
809
|
|
|
1
|
|
|
|
|
329
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub meta { +{ |
14
|
1
|
|
|
1
|
0
|
14
|
v => 2, |
15
|
|
|
|
|
|
|
} } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub get_hooks { |
18
|
1
|
|
|
1
|
0
|
12
|
my %plugin_conf = @_; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
return { |
21
|
|
|
|
|
|
|
create_formatter => [ |
22
|
|
|
|
|
|
|
__PACKAGE__, # key |
23
|
|
|
|
|
|
|
50, # priority |
24
|
|
|
|
|
|
|
sub { # hook |
25
|
2
|
|
|
2
|
|
2211
|
my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook" |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $formatter = sub { |
28
|
5
|
100
|
|
|
|
286
|
return $_[0] if @_ < 2; |
29
|
4
|
|
|
|
|
8
|
my $fmt = shift; |
30
|
4
|
|
|
|
|
4
|
my @args; |
31
|
4
|
|
|
|
|
12
|
for my $i (0..$#_) { |
32
|
6
|
100
|
100
|
|
|
29
|
if ($i == 0 && ref $_[$i] eq 'HASH') { |
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
33
|
2
|
|
|
|
|
3
|
my $orig = $_[$i]; |
34
|
2
|
|
|
|
|
3
|
my $dumped = {}; |
35
|
2
|
|
|
|
|
7
|
for my $k (keys %$orig) { |
36
|
2
|
|
|
|
|
3
|
my $v = $orig->{$k}; |
37
|
|
|
|
|
|
|
# XXX code duplication'ish |
38
|
2
|
50
|
|
|
|
8
|
if (!defined($v)) { |
|
|
100
|
|
|
|
|
|
39
|
0
|
|
|
|
|
0
|
$dumped->{$k} = ''; |
40
|
|
|
|
|
|
|
} elsif (ref $v) { |
41
|
|
|
|
|
|
|
require Log::ger::Util |
42
|
1
|
50
|
|
|
|
3
|
unless $Log::ger::_dumper; |
43
|
1
|
|
|
|
|
14
|
$dumped->{$k} = Log::ger::Util::_dump($v); |
44
|
|
|
|
|
|
|
} else { |
45
|
1
|
|
|
|
|
3
|
$dumped->{$k} = $v; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
2
|
|
|
|
|
43
|
push @args, $dumped; |
49
|
|
|
|
|
|
|
} elsif (!defined($_[$i])) { |
50
|
0
|
|
|
|
|
0
|
push @args, ''; |
51
|
|
|
|
|
|
|
} elsif (ref $_[$i]) { |
52
|
2
|
100
|
|
|
|
9
|
require Log::ger::Util unless $Log::ger::_dumper; |
53
|
2
|
|
|
|
|
7
|
push @args, Log::ger::Util::_dump($_[$i]); |
54
|
|
|
|
|
|
|
} else { |
55
|
2
|
|
|
|
|
5
|
push @args, $_[$i]; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
4
|
|
|
|
|
2238
|
sprintfn $fmt, @args; |
59
|
2
|
|
|
|
|
7
|
}; |
60
|
2
|
|
|
|
|
7
|
[$formatter]; |
61
|
1
|
|
|
|
|
8
|
}], |
62
|
|
|
|
|
|
|
}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
# ABSTRACT: Use Text::sprintfn for formatting instead of sprintf |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |