Client/Role/LoggerWrapper.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 60.0% 6 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 91.6% 11 / 12 Podpod 100% 1 / 1 totaltotal 81.5% 53 / 65 CC 7 SCAR 10.0
CC
7
Cov
84%
log_msg
5.7
__ANON__
3.4
__ANON__
1.1
CRAP 2.7
« Client/Utils.pm ↑ Summary Client/Error/Provider.pm »
1 package OIDC::Client::Role::LoggerWrapper;
2 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use List::Util qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =encoding utf8
12  
13 =head1 NAME
14  
15 OIDC::Client::Role::LoggerWrapper - Logger wrapper
16  
17 =head1 DESCRIPTION
18  
19 This Moose role is used to manage different loggers, mainly because some
20 only accept the C<warn> method, while others only the C<warning> method.
21  
22 =cut
23  
24 subtype 'LoggerObject',
25 as 'Object',
26 168 ▶ where {
Subroutine __ANON__: called CC=3 SCAR=12.3
27 168 my $obj = $_;
28 168 ▶ (all { $obj->can($_) } qw/debug info error/)
Subroutine __ANON__: called CC=1 SCAR=0.6
Branch: 1 branch
BranchTrueFalseTotal
&all(sub { $obj->can($_); } , "debug", "info", "error") and $obj->can("warning") || $obj->can("warn") 168 0 168
Condition50%3/6
&all(sub { $obj->can($_); } , 'debug', 'info', 'error') && ($obj->can('warning') || $obj->can('warn'))
!ll&&!rl&&r
00168
$obj->can("warning") or $obj->can("warn")
l!l&&r!l&&!r
158100
MC/DC0%0/3
&all(sub { $obj->can($_); } , 'debug', 'info', 'error') && ($obj->can('warning') || $obj->can('warn'))
&all(sub { $obj->can($_); } , 'debug', 'info', 'error') $obj->can("warning") $obj->can("warn")
Truth table50%2/4
A && B or C
A= &all(sub { $obj->can($_); } , 'debug', 'info', 'error')B= $obj->can("warning")C= $obj->can("warn")
ABCresult
0XX0
1000
11X1
1011
29 && ($obj->can('warning') || $obj->can('warn'));
30 },
31 0 ▶ message { "The 'logger' attribute you provided is not a logger object" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
32  
33 7 has 'log' => (
34 is => 'ro',
35 isa => 'LoggerObject',
36 required => 1,
37 );
38  
39 =head1 METHODS
40  
41 =head2 log_msg( $level, $message )
42  
43 $self->log_msg(info => "my log message");
44  
45 Log the message.
46  
47 $level only accepts C<debug>, C<info>, C<warning>, C<warn> or C<error> level.
48  
49 =cut
50  
51 181 ▶sub log_msg ($self, $level, $message) {
Subroutine log_msg: called CC=5 SCAR=17.4
Pod documented
52  
53 181 ▶ my $method = $level =~ /^(debug|info|error)$/ ? $level
Branch: 4 branches
BranchTrueFalseTotal
my $method = $level =~ /^(debug|info|error)$/ ? $level : ($level =~ /^warn(ing)?$/ ? $self->log->can("warning") ? "warning" : "warn" : undef) or croak("log_msg() only accepts debug, info, warning, warn or error level, not '${level}'") 181 0 181
$level =~ /^(debug|info|error)$/ ? : 176 5 181
$level =~ /^warn(ing)?$/ ? : 5 0 5
$self->log->can('warning') ? : 5 0 5
54 : $level =~ /^warn(ing)?$/ ? $self->log->can('warning') ? 'warning' : 'warn'
55 : undef
56 or croak("log_msg() only accepts debug, info, warning, warn or error level, not '$level'");
57  
58 181 $self->log->$method($message);
59 }
60  
61 7 1;
« Client/Utils.pm ↑ Summary Client/Error/Provider.pm »