blib/lib/Log/ger/Output/Callback.pm

filter: Statementstmt 84.3% 27 / 32 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 0.0% 0 / 2 totaltotal 74.5% 38 / 51 CC 5 SCAR 7.9
CC
5
Cov
78%
get_hooks
3.4
__ANON__
3.1
__ANON__
2.0
CRAP 2.2
↑ Summary
1 package Log::ger::Output::Callback;
2  
3 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 2 our $DATE = '2020-03-11'; # DATE
5 2 our $DIST = 'Log-ger-Output-Callback'; # DIST
6 2 our $VERSION = '0.009'; # VERSION
7  
8 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub meta { +{
Subroutine meta: called CC=1 SCAR=0.0
Pod undocumented
13 1 v => 2,
14 } }
15  
16 1 ▶sub get_hooks {
Subroutine get_hooks: called CC=3 SCAR=12.2
Pod undocumented
17 1 my %plugin_conf = @_;
18  
19 1 my $hooks = {};
20  
21 1 ▶ if ($plugin_conf{logging_cb}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin_conf{"logging_cb"}) 1 0 1
22 $hooks->{create_outputter} = [
23 __PACKAGE__, # key
24 # we want to handle all levels, thus we need to be higher priority
25 # than default Log::ger hooks (10) which will install null loggers
26 # for less severe levels.
27 9, # priority
28 6 ▶ sub { # hook
Subroutine __ANON__: called CC=1 SCAR=0.1
29 6 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
30 3 ▶ my $outputter = sub {
Subroutine __ANON__: called CC=3 SCAR=11.4
31 3 my ($per_target_conf, $msg, $per_msg_conf) = @_;
32 3 ▶ my $level = $per_msg_conf ? $per_msg_conf->{level} : undef; $level = $hook_args{level} if !defined $level;
Branch: 2 branches
BranchTrueFalseTotal
$per_msg_conf ? : 0 3 3
unless defined $level 3 0 3
33 3 $plugin_conf{logging_cb}->($per_target_conf, $level, $msg, $per_msg_conf);
34 6 };
35 6 [$outputter];
36 },
37 1 ];
38 }
39  
40 1 ▶ if ($plugin_conf{detection_cb}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plugin_conf{"detection_cb"}) 0 1 1
41 $hooks->{create_level_checker} = [
42 __PACKAGE__, # key
43 9, # priority
44 0 ▶ sub { # hook
Subroutine __ANON__: not called CC=1 SCAR=6.9
45 0 my %hook_args = @_; # see Log::ger::Manual::Internals/"Arguments passed to hook"
46 0 ▶ my $level_checker = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
47 0 $plugin_conf{detection_cb}->($hook_args{level});
48 0 };
49 0 [$level_checker];
50 },
51 0 ];
52 }
53  
54 1 return $hooks;
55 }
56  
57 2 1;
58 # ABSTRACT: Send logs to a subroutine
59  
60 __END__
↑ Summary