Dispatchouli/Proxy.pm

filter: Statementstmt 83.5% 71 / 85 Branchbran 73.5% 25 / 34 Conditioncond 63.6% 7 / 11 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 71.4% 30 / 42 Podpod 0.0% 0 / 30 totaltotal 64.5% 135 / 209 CC 23 SCAR 9.2
CC
23
Cov
79%
set_muted
6.0
log_fatal
6.0
proxy
5.0
CRAP 2.5
« Dispatchouli/Global.pm ↑ Summary Fmt/Test.pm »
1 7 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Log::Dispatchouli::Proxy 3.101;
4 # ABSTRACT: a simple wrapper around Log::Dispatch
5  
6 # Not dangerous. Accepted without change.
7 7 ▶use experimental 'postderef', 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 7 ▶use Log::Fmt ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Params::Util qw(_ARRAY0 _HASH0);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 #pod =head1 DESCRIPTION
13 #pod
14 #pod A Log::Dispatchouli::Proxy object is the child of a L<Log::Dispatchouli> logger
15 #pod (or another proxy) and relays log messages to its parent. It behaves almost
16 #pod identically to a Log::Dispatchouli logger, and you should refer there for more
17 #pod of its documentation.
18 #pod
19 #pod Here are the differences:
20 #pod
21 #pod =begin :list
22 #pod
23 #pod * You can't create a proxy with C<< ->new >>, only by calling C<< ->proxy >> on an existing logger or proxy.
24 #pod
25 #pod * C<set_debug> will set a value for the proxy; if none is set, C<get_debug> will check the parent's setting; C<clear_debug> will clear any set value on this proxy
26 #pod
27 #pod * C<log_debug> messages will be redispatched to C<log> (to the 'debug' logging level) to prevent parent loggers from dropping them due to C<debug> setting differences
28 #pod
29 #pod =end :list
30 #pod
31 #pod =cut
32  
33 21 ▶sub _new ($class, $arg) {
Subroutine _new: called CC=1 SCAR=0.0
34 my $guts = {
35 parent => $arg->{parent},
36 logger => $arg->{logger},
37 debug => $arg->{debug},
38 proxy_prefix => $arg->{proxy_prefix},
39 proxy_ctx => $arg->{proxy_ctx},
40 21 };
41  
42 21 bless $guts => $class;
43 }
44  
45 10 ▶sub proxy ($self, $arg = undef) {
Subroutine proxy: called CC=5 SCAR=16.1
Pod undocumented
46 10 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
100
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
47  
48 10 my @proxy_ctx;
49  
50 10 ▶ if (my $ctx = $arg->{proxy_ctx}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ctx = $arg->{"proxy_ctx"}) 8 2 10
51 @proxy_ctx = _ARRAY0($ctx)
52 ? (@proxy_ctx, @$ctx)
53 8 ▶ : (@proxy_ctx, $ctx->%{ sort keys %$ctx });
Branch: 1 branch
BranchTrueFalseTotal
&_ARRAY0($ctx) ? : 1 7 8
54 }
55  
56 my $prox = (ref $self)->_new({
57 parent => $self,
58 logger => $self->logger,
59 debug => $arg->{debug},
60 muted => $arg->{muted},
61 proxy_prefix => $arg->{proxy_prefix},
62 10 proxy_ctx => \@proxy_ctx,
63 });
64 }
65  
66 51 ▶sub parent ($self) { $self->{parent} }
Subroutine parent: called CC=1 SCAR=0.0
Pod undocumented
67 32 ▶sub logger ($self) { $self->{logger} }
Subroutine logger: called CC=1 SCAR=0.0
Pod undocumented
68  
69 1 ▶sub ident ($self) { $self->{logger}->ident }
Subroutine ident: called CC=1 SCAR=0.0
Pod undocumented
70 0 ▶sub config_id ($self) { $self->{logger}->config_id }
Subroutine config_id: not called CC=1 SCAR=6.9
Pod undocumented
71  
72 27 ▶sub get_prefix ($self) { $self->{prefix} }
Subroutine get_prefix: called CC=1 SCAR=0.0
Pod undocumented
73 4 ▶sub set_prefix ($self, $prefix) { $self->{prefix} = $prefix }
Subroutine set_prefix: called CC=1 SCAR=0.0
Pod undocumented
74 0 ▶sub clear_prefix ($self) { undef $self->{prefix} }
Subroutine clear_prefix: not called CC=1 SCAR=6.9
Pod undocumented
75 0 ▶sub unset_prefix ($self) { $self->clear_prefix }
Subroutine unset_prefix: not called CC=1 SCAR=6.9
Pod undocumented
76  
77 4 ▶sub set_debug ($self, $bool) { $self->{debug} = $bool ? 1 : 0 }
Subroutine set_debug: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 2 2 4
78 0 ▶sub clear_debug ($self) { undef $self->{debug} }
Subroutine clear_debug: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 13 ▶sub get_debug ($self) {
Subroutine get_debug: called CC=2 SCAR=6.9
Pod undocumented
81 13 ▶ return $self->{debug} if defined $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"debug"} 8 5 13
82 5 return $self->parent->get_debug;
83 }
84  
85 0 ▶sub is_debug ($self) { $self->get_debug }
Subroutine is_debug: not called CC=1 SCAR=6.9
Pod undocumented
86 0 ▶sub is_info ($) { 1 }
Subroutine is_info: not called CC=1 SCAR=6.9
Pod undocumented
87 0 ▶sub is_fatal ($) { 1 }
Subroutine is_fatal: not called CC=1 SCAR=6.9
Pod undocumented
88  
89 3 ▶sub mute ($self) { $self->{muted} = 1 }
Subroutine mute: called CC=1 SCAR=0.0
Pod undocumented
90 1 ▶sub unmute ($self) { $self->{muted} = 0 }
Subroutine unmute: called CC=1 SCAR=0.0
Pod undocumented
91  
92 0 ▶sub set_muted ($self, $bool) { $self->{muted} = $bool ? 1 : 0 }
Subroutine set_muted: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$bool ? : 0 0 0
93 6 ▶sub clear_muted ($self) { undef $self->{muted} }
Subroutine clear_muted: called CC=1 SCAR=0.0
Pod undocumented
94  
95 26 ▶sub _get_local_muted ($self) { $self->{muted} }
Subroutine _get_local_muted: called CC=1 SCAR=0.0
96  
97 11 ▶sub get_muted ($self) {
Subroutine get_muted: called CC=2 SCAR=7.2
Pod undocumented
98 11 ▶ return $self->{muted} if defined $self->{muted};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"muted"} 0 11 11
99 11 return $self->parent->get_muted;
100 }
101  
102 27 ▶sub _get_all_prefix ($self, $arg) {
Subroutine _get_all_prefix: called CC=2 SCAR=6.9
103 return [
104 $self->{proxy_prefix},
105 $self->get_prefix,
106 6 _ARRAY0($arg->{prefix}) ? @{ $arg->{prefix} } : $arg->{prefix}
107 27 ▶ ];
Branch: 1 branch
BranchTrueFalseTotal
&_ARRAY0($arg->{'prefix'}) ? : 6 21 27
108 }
109  
110 6 ▶sub flog_messages ($self, @rest) {
Subroutine flog_messages: called CC=2 SCAR=6.9
Pod undocumented
111 6 ▶ my $arg = _HASH0($rest[0]) ? shift(@rest) : {};
Branch: 1 branch
BranchTrueFalseTotal
&_HASH0($rest[0]) ? : 4 2 6
112 6 local $arg->{prefix} = $self->_get_all_prefix($arg);
113  
114 6 $self->parent->flog_messages($arg, @rest);
115 }
116  
117 26 ▶sub log ($self, @rest) {
Subroutine log: called CC=4 SCAR=13.9
Pod undocumented
118 26 ▶ my $arg = _HASH0($rest[0]) ? shift(@rest) : {};
Branch: 1 branch
BranchTrueFalseTotal
&_HASH0($rest[0]) ? : 12 14 26
119  
120 26 ▶ return if $self->_get_local_muted and ! $arg->{fatal};
Branch: 1 branch
BranchTrueFalseTotal
if $self->_get_local_muted and not $arg->{"fatal"} 5 21 26
Condition66%2/3
$self->_get_local_muted and not $arg->{"fatal"}
!ll&&!rl&&r
2105
MC/DC50%1/2
$self->_get_local_muted and not $arg->{"fatal"}
$self->_get_local_muted not $arg->{"fatal"}
Truth table66%2/3
A and not(B)
A= $self->_get_local_mutedB= not $arg->{"fatal"}
ABresult
0X0
100
111
121  
122 21 local $arg->{prefix} = $self->_get_all_prefix($arg);
123  
124 21 $self->parent->log($arg, @rest);
125 }
126  
127 0 ▶sub log_fatal ($self, @rest) {
Subroutine log_fatal: not called CC=2 SCAR=17.9
Pod undocumented
128 0 ▶ my $arg = _HASH0($rest[0]) ? shift(@rest) : {};
Branch: 1 branch
BranchTrueFalseTotal
&_HASH0($rest[0]) ? : 0 0 0
129 0 local $arg->{fatal} = 1;
130  
131 0 $self->log($arg, @rest);
132 }
133  
134 6 ▶sub log_debug ($self, @rest) {
Subroutine log_debug: called CC=4 SCAR=14.0
Pod undocumented
135 6 my $debug = $self->get_debug;
136 6 ▶ return if defined $debug and ! $debug;
Branch: 1 branch
BranchTrueFalseTotal
if defined $debug and not $debug 3 3 6
Condition66%2/3
defined $debug and not $debug
!ll&&!rl&&r
033
MC/DC50%1/2
defined $debug and not $debug
defined $debug not $debug
Truth table66%2/3
A and not(B)
A= defined $debugB= not $debug
ABresult
0X0
100
111
137  
138 3 ▶ my $arg = _HASH0($rest[0]) ? shift(@rest) : {};
Branch: 1 branch
BranchTrueFalseTotal
&_HASH0($rest[0]) ? : 0 3 3
139 3 local $arg->{level} = 'debug';
140  
141 3 $self->log($arg, @rest);
142 }
143  
144 10 ▶sub _compute_proxy_ctx_kvstr_aref ($self) {
Subroutine _compute_proxy_ctx_kvstr_aref: called CC=3 SCAR=11.2
145 10 ▶ return $self->{proxy_ctx_kvstr} //= do {
Condition66%2/3
$self->{"proxy_ctx_kvstr"} //= do { my(@kvstr) = @{$self->parent->_compute_proxy_ctx_kvstr_aref}; if ($self->{"proxy_ctx"}) { my $our_kv = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref($self->{"proxy_ctx"}); push @kvstr, @$our_kv; } ; \@kvstr }
l!l&&r!l&&!r
460
MC/DC0%0/2
$self->{"proxy_ctx_kvstr"} //= do { my(@kvstr) = @{$self->parent->_compute_proxy_ctx_kvstr_aref}; if ($self->{"proxy_ctx"}) { my $our_kv = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref($self->{"proxy_ctx"}); push @kvstr, @$our_kv; } ; \@kvstr }
$self->{"proxy_ctx_kvstr"} do { my(@kvstr) = @{$self->parent->_compute_proxy_ctx_kvstr_aref}; if ($self->{"proxy_ctx"}) { my $our_kv = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref($self->{"proxy_ctx"}); push @kvstr, @$our_kv; } ; \@kvstr }
Truth table66%2/3
A //= B
A= $self->{"proxy_ctx_kvstr"}B= do { my(@kvstr) = @{$self->parent->_compute_proxy_ctx_kvstr_aref}; if ($self->{"proxy_ctx"}) { my $our_kv = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref($self->{"proxy_ctx"}); push @kvstr, @$our_kv; } ; \@kvstr }
ABresult
1X1
011
000
146 6 my @kvstr = $self->parent->_compute_proxy_ctx_kvstr_aref->@*;
147  
148 6 ▶ if ($self->{proxy_ctx}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"proxy_ctx"}) 6 0 6
149 6 my $our_kv = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref($self->{proxy_ctx});
150 6 push @kvstr, @$our_kv;
151 }
152  
153 6 \@kvstr;
154 };
155 }
156  
157 7 ▶sub fmt_event ($self, $type, $data) {
Subroutine fmt_event: called CC=2 SCAR=7.1
Pod undocumented
158 my $kv_aref = $self->logger->_log_fmt_package->_pairs_to_kvstr_aref([
159 event => $type,
160 7 ▶ (_ARRAY0($data) ? @$data : $data->%{ sort keys %$data })
Branch: 1 branch
BranchTrueFalseTotal
&_ARRAY0($data) ? : 7 0 7
161 ]);
162  
163 7 splice @$kv_aref, 1, 0, $self->_compute_proxy_ctx_kvstr_aref->@*;
164  
165 7 return join q{ }, @$kv_aref;
166 }
167  
168 7 ▶sub log_event ($self, $event, $data) {
Subroutine log_event: called CC=2 SCAR=7.1
Pod undocumented
169 7 ▶ return if $self->get_muted;
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_muted 0 7 7
170  
171 7 my $message = $self->fmt_event($event, $data);
172  
173 7 $self->logger->dispatcher->log(
174 level => 'info',
175 message => $message,
176 );
177 }
178  
179 4 ▶sub log_debug_event ($self, $event, $data) {
Subroutine log_debug_event: called CC=2 SCAR=6.9
Pod undocumented
180 4 ▶ return unless $self->get_debug;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_debug 1 3 4
181  
182 3 return $self->log_event($event, $data);
183 }
184  
185 0 ▶sub info ($self, @rest) { $self->log(@rest); }
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
186 0 ▶sub fatal ($self, @rest) { $self->log_fatal(@rest); }
Subroutine fatal: not called CC=1 SCAR=6.9
Pod undocumented
187 0 ▶sub debug ($self, @rest) { $self->log_debug(@rest); }
Subroutine debug: not called CC=1 SCAR=6.9
Pod undocumented
188  
189 use overload
190 1 ▶ '&{}' => sub { my ($self) = @_; sub { $self->log(@_) } },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
191 7 fallback => 1,
192 7 ;
193  
194 7 1;
195  
196 __END__
« Dispatchouli/Global.pm ↑ Summary Fmt/Test.pm »