Dispatch/Base.pm

filter: Statementstmt 100% 51 / 51 Branchbran 80.0% 8 / 10 Conditioncond 80.0% 4 / 5 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 91.4% 75 / 82 CC 9 SCAR 8.5
CC
9
Cov
95%
level_is_valid
4.0
add_callback
3.0
remove_callback
2.0
CRAP 2.3
« Dispatch/ApacheLog.pm ↑ Summary Dispatch/Conflicts.pm »
1 package Log::Dispatch::Base;
2  
3 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 33 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 use Log::Dispatch::Vars
8 33 ▶ qw( %CanonicalLevelNames %LevelNamesToNumbers @OrderedLevels );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 33 ▶use Scalar::Util qw( refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 33 our $VERSION = '2.71';
12  
13 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
14 191 ▶sub _level_as_number {
Subroutine _level_as_number: called CC=2 SCAR=6.9
15 191 my $self = shift;
16 191 my $level = shift;
17  
18 191 my $level_name = $self->level_is_valid($level);
19 190 ▶ return unless $level_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $level_name 1 189 190
20  
21 189 return $LevelNamesToNumbers{$level_name};
22 }
23 ## use critic
24  
25 206 ▶sub level_is_valid {
Subroutine level_is_valid: called CC=4 SCAR=13.9
Pod undocumented
26 206 shift;
27 206 my $level = shift;
28  
29 206 ▶ if ( !defined $level ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $level) 1 205 206
30 1 Carp::croak('Logging level was not provided');
31 }
32  
33 205 ▶ if ( $level =~ /\A[0-9]+\z/ && $level <= $#OrderedLevels ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level =~ /\A[0-9]+\z/ and $level <= $#Log::Dispatch::Base::OrderedLevels) 15 190 205
Condition66%2/3
$level =~ /\A[0-9]+\z/ and $level <= $#Log::Dispatch::Base::OrderedLevels
!ll&&!rl&&r
190015
MC/DC50%1/2
$level =~ /\A[0-9]+\z/ and $level <= $#Log::Dispatch::Base::OrderedLevels
$level =~ /\A[0-9]+\z/ $level <= $#Log::Dispatch::Base::OrderedLevels
Truth table66%2/3
A and B
A= $level =~ /\A[0-9]+\z/B= $level <= $#Log::Dispatch::Base::OrderedLevels
ABresult
0X0
100
111
34 15 return $OrderedLevels[$level];
35 }
36  
37 190 return $CanonicalLevelNames{$level};
38 }
39  
40 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
41 90 ▶sub _apply_callbacks {
Subroutine _apply_callbacks: called CC=2 SCAR=6.9
42 90 my $self = shift;
43 90 my %p = @_;
44  
45 90 my $msg = delete $p{message};
46 90 for my $cb ( @{ $self->{callbacks} } ) {
47 93 $msg = $cb->( message => $msg, %p );
48 }
49  
50 90 return $msg;
51 }
52  
53 5 ▶sub add_callback {
Subroutine add_callback: called CC=3 SCAR=11.0
Pod undocumented
54 5 my $self = shift;
55 5 my $value = shift;
56  
57 5 ▶ Carp::carp("given value $value is not a valid callback")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "CODE" 0 5 5
58 unless ref $value eq 'CODE';
59  
60 5 ▶ $self->{callbacks} ||= [];
Condition100%2/2
$self->{"callbacks"} ||= []
l!l
32
MC/DC100%1/1
$self->{"callbacks"} ||= []
$self->{"callbacks"}
Truth table100%2/2
A
A= $self->{"callbacks"}
Aresult
11
00
61 5 push @{ $self->{callbacks} }, $value;
62  
63 5 return;
64 }
65  
66 2 ▶sub remove_callback {
Subroutine remove_callback: called CC=2 SCAR=7.0
Pod undocumented
67 2 my $self = shift;
68 2 my $cb = shift;
69  
70 2 ▶ Carp::carp("given value $cb is not a valid callback")
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cb eq "CODE" 0 2 2
71 unless ref $cb eq 'CODE';
72  
73 2 my $cb_id = refaddr $cb;
74 $self->{callbacks}
75 2 = [ grep { refaddr $_ ne $cb_id } @{ $self->{callbacks} } ];
76  
77 2 return;
78 }
79  
80 33 1;
81  
82 # ABSTRACT: Code shared by dispatch and output objects.
83  
84 __END__
« Dispatch/ApacheLog.pm ↑ Summary Dispatch/Conflicts.pm »