ger/Format/MultilevelLog.pm

filter: Statementstmt 81.4% 35 / 43 Branchbran 40.0% 4 / 10 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 72.2% 52 / 72 CC 9 SCAR 15.3
CC
9
Cov
72%
__ANON__
12.4
get_hooks
3.5
BEGIN
2.0
CRAP 4.6
« ger/Plugin/MultilevelLog.pm ↑ Summary ger/Filter/Code.pm »
1 package Log::ger::Format::MultilevelLog;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Log::ger::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
9 2 our $DATE = '2023-12-29'; # DATE
10 2 our $DIST = 'Log-ger'; # DIST
11 2 our $VERSION = '0.042'; # VERSION
12  
13 1 ▶sub meta { +{
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
14 1 v => 2,
15 } }
16  
17 1 ▶sub get_hooks {
Subroutine get_hooks: called CC=3 SCAR=12.5
Pod undocumented
18 1 my %conf = @_;
19  
20 1 ▶ my $sub_name = $conf{sub_name} || 'log';
Condition50%1/2
$conf{'sub_name'} || 'log'
l!l
01
MC/DC0%0/1
$conf{'sub_name'} || 'log'
$conf{'sub_name'}
Truth table50%1/2
A
A= $conf{'sub_name'}
Aresult
11
00
21 1 ▶ my $method_name = $conf{method_name} || 'log';
Condition50%1/2
$conf{'method_name'} || 'log'
l!l
01
MC/DC0%0/1
$conf{'method_name'} || 'log'
$conf{'method_name'}
Truth table50%1/2
A
A= $conf{'method_name'}
Aresult
11
00
22  
23 return {
24 create_filter => [
25 __PACKAGE__, # key
26 50, # priority
27 2 ▶ sub { # hook
Subroutine __ANON__: called CC=1 SCAR=0.0
28 2 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
29  
30 2 ▶ my $filter = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
31 2 my $level = Log::ger::Util::numeric_level(shift);
32 2 ▶ return 0 unless $level <= $Log::ger::Current_Level;
Branch: 1 branch
BranchTrueFalseTotal
unless $level <= $Log::ger::Current_Level 1 1 2
33 1 {level=>$level};
34 2 };
35  
36 2 [$filter, 0, 'ml'];
37 },
38 ],
39  
40 create_formatter => [
41 __PACKAGE__, # key
42 50, # priority
43 2 ▶ sub { # hook
Subroutine __ANON__: called CC=1 SCAR=1.8
44 2 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
45  
46 my $formatter =
47  
48 # just like the default formatter, except it accepts first
49 # argument (level)
50 1 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=25.2
51 1 shift; # level
52 1 ▶ return $_[0] if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 1 0 1
53 0 my $fmt = shift;
54 0 my @args;
55 0 for (@_) {
56 0 ▶ if (!defined($_)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $_) { } 0 0 0
elsif (ref $_) { } 0 0 0
57 0 push @args, '<undef>';
58 } elsif (ref $_) {
59 0 push @args, Log::ger::Util::_dump($_);
60 } else {
61 0 push @args, $_;
62 }
63 }
64 # redefine is just a dummy category for perls < 5.22
65 # which don't have 'redundant' yet
66 2 ▶ no warnings ($warnings::Bits{'redundant'} ? 'redundant' : 'redefine');
Subroutine BEGIN: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$warnings::Bits{'redundant'} ? : 2 0 2
67 0 sprintf $fmt, @args;
68 2 };
69  
70 2 [$formatter, 0, 'ml'];
71 },
72 ],
73  
74 create_routine_names => [
75 __PACKAGE__, # key
76 50, # priority
77 2 ▶ sub { # hook
Subroutine __ANON__: called CC=1 SCAR=0.0
78 2 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
79 return [{
80 logger_subs => [[$sub_name , undef, 'ml', undef, 'ml']],
81 logger_methods => [[$method_name, undef, 'ml', undef, 'ml']],
82 2 }, $conf{exclusive}];
83 },
84 1 ],
85 };
86 }
87  
88 2 1;
89 # ABSTRACT: Create a log($LEVEL, ...) subroutine/method
90  
91 __END__
« ger/Plugin/MultilevelLog.pm ↑ Summary ger/Filter/Code.pm »