Log4perl/Appender/TestBuffer.pm

filter: Statementstmt 97.0% 33 / 34 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 16.6% 1 / 6 totaltotal 79.0% 49 / 62 CC 7 SCAR 8.2
CC
7
Cov
87%
new
3.1
log
3.1
by_name
2.0
CRAP 2.3
« Log4perl/Layout/PatternLayout/Multiline.pm ↑ Summary Log4perl/Appender/TestFileCreeper.pm »
1 package Log::Log4perl::Appender::TestBuffer;
2 30 our @ISA = qw(Log::Log4perl::Appender);
3  
4 ##################################################
5 # Log dispatcher writing to a string buffer
6 # For testing.
7 # This is like having a Log::Log4perl::Appender::TestBuffer
8 ##################################################
9  
10 30 our %POPULATION = ();
11 30 our $LOG_PRIORITY = 0;
12 30 our $DESTROY_MESSAGES = "";
13  
14 ##################################################
15 110 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod documented
16 ##################################################
17 110 my $proto = shift;
18 110 ▶ my $class = ref $proto || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
01100
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
19 110 my %params = @_;
20  
21 110 my $self = {
22 name => "unknown name",
23 %params,
24 };
25  
26 110 bless $self, $class;
27  
28 110 ▶ $self->{stderr} = exists $params{stderr} ? $params{stderr} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $params{'stderr'} ? : 0 110 110
29 110 $self->{buffer} = "";
30  
31 110 $POPULATION{$self->{name}} = $self;
32  
33 110 return $self;
34 }
35  
36 ##################################################
37 201 ▶sub log {
Subroutine log: called CC=3 SCAR=11.2
Pod undocumented
38 ##################################################
39 201 my $self = shift;
40 201 my %params = @_;
41  
42 201 ▶ if( !defined $params{level} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $params{"level"}) 0 201 201
43 0 die "No level defined in log() call of " . __PACKAGE__;
44 }
45 201 ▶ $self->{buffer} .= "[$params{level}]: " if $LOG_PRIORITY;
Branch: 1 branch
BranchTrueFalseTotal
if $LOG_PRIORITY 5 196 201
46 201 $self->{buffer} .= $params{message};
47 }
48  
49 ###########################################
50 2 ▶sub clear {
Subroutine clear: called CC=1 SCAR=0.0
Pod undocumented
51 ###########################################
52 2 my($self) = @_;
53  
54 2 $self->{buffer} = "";
55 }
56  
57 ##################################################
58 292 ▶sub buffer {
Subroutine buffer: called CC=2 SCAR=6.9
Pod undocumented
59 ##################################################
60 292 my($self, $new) = @_;
61  
62 292 ▶ if(defined $new) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 98 194 292
63 98 $self->{buffer} = $new;
64 }
65  
66 292 return $self->{buffer};
67 }
68  
69 ##################################################
70 63 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod undocumented
71 ##################################################
72 63 my($self) = @_;
73  
74 63 %POPULATION = ();
75 63 $self->{buffer} = "";
76 }
77  
78 ##################################################
79 70 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
80 ##################################################
81 70 my($self) = @_;
82  
83 70 $DESTROY_MESSAGES .= __PACKAGE__ . " destroyed";
84  
85 #this delete() along with &reset() above was causing
86 #Attempt to free unreferenced scalar at
87 #blib/lib/Log/Log4perl/TestBuffer.pm line 69.
88 #delete $POPULATION{$self->name};
89 }
90  
91 ##################################################
92 92 ▶sub by_name {
Subroutine by_name: called CC=2 SCAR=7.1
Pod undocumented
93 ##################################################
94 92 my($self, $name) = @_;
95  
96 # Return a TestBuffer by appender name. This is useful if
97 # test buffers are created behind our back (e.g. via the
98 # Log4perl config file) and later on we want to
99 # retrieve an instance to query its content.
100  
101 92 ▶ die "No name given" unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 92 92
102  
103 92 return $POPULATION{$name};
104  
105 }
106  
107 30 1;
108  
109 __END__
« Log4perl/Layout/PatternLayout/Multiline.pm ↑ Summary Log4perl/Appender/TestFileCreeper.pm »