Agent/Prefixer.pm

filter: Statementstmt 69.5% 16 / 23 Branchbran 78.5% 11 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 8 totaltotal 52.5% 31 / 59 CC 9 SCAR 17.9
CC
9
Cov
70%
prefixing_string
9.7
prefix
2.0
showpid
2.0
CRAP 6.0
« Agent/Driver/File.pm ↑ Summary Agent/Driver/Datum.pm »
1 ###########################################################################
2 #
3 # Prefixer.pm
4 #
5 # Copyright (C) 1999 Raphael Manfredi.
6 # Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
7 # all rights reserved.
8 #
9 # See the README file included with the
10 # distribution for license information.
11 #
12 ##########################################################################
13  
14 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 ########################################################################
17 package Log::Agent::Prefixer;
18  
19 #
20 # Ancestor for logging channels wishing to implement native prefixing
21 #
22  
23 #
24 # Attribute access: those attributes must be filled by our heirs
25 #
26  
27 0 ▶sub prefix { $_[0]->{'prefix'} }
Subroutine prefix: not called CC=1 SCAR=6.9
Pod undocumented
28 64 ▶sub stampfmt { $_[0]->{'stampfmt'} }
Subroutine stampfmt: called CC=1 SCAR=0.0
Pod undocumented
29 0 ▶sub showpid { $_[0]->{'showpid'} }
Subroutine showpid: not called CC=1 SCAR=6.9
Pod undocumented
30 0 ▶sub no_ucfirst { $_[0]->{'no_ucfirst'} }
Subroutine no_ucfirst: not called CC=1 SCAR=6.9
Pod undocumented
31 0 ▶sub no_prefixing { $_[0]->{'no_prefixing'} }
Subroutine no_prefixing: not called CC=1 SCAR=6.9
Pod undocumented
32 0 ▶sub no_newline { $_[0]->{'no_newline'} }
Subroutine no_newline: not called CC=1 SCAR=6.9
Pod undocumented
33 0 ▶sub crlf { $_[0]->{'crlf'} }
Subroutine crlf: not called CC=1 SCAR=6.9
Pod undocumented
34  
35 #
36 # ->prefixing_string
37 #
38 # Compute prefixing string: stamping and "prefix: " to be emitted before
39 # the logged string.
40 #
41 # Usage:
42 #
43 # $str = $self->prefixing_string(); # no ucfirst support possible
44 # $str = $self->prefixing_string(\$log_message);
45 #
46 # Leading char of to-be-logged string is upper-cased in-place if
47 # neither prefix nor pid are present, and behaviour was not disabled
48 # via a -no_ucfirst, and the second call form with a scalar ref is used.
49 #
50 77 ▶sub prefixing_string {
Subroutine prefixing_string: called CC=9 SCAR=22.7
Pod undocumented
51 77 my $self = shift;
52  
53 #
54 # This routine is called often...
55 # Bypass the attribute access routines.
56 #
57  
58 77 my $prefix = $self->{prefix};
59 77 ▶ $prefix = '' unless defined $prefix;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $prefix 14 63 77
60 77 ▶ if ($self->{showpid}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'showpid'}) { } 19 58 77
elsif ($prefix eq '') { } 14 44 58
61 19 ▶ if ($prefix eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefix eq '') { } 0 19 19
62 0 $prefix = $$;
63 } else {
64 19 $prefix .= "[$$]";
65 }
66 } elsif ($prefix eq '') {
67 14 my $rstr = $_[0];
68 14 ▶ $$rstr =~ s/^(.)/\u$1/ if ref $rstr && !$self->{no_ucfirst};
Branch: 1 branch
BranchTrueFalseTotal
if ref $rstr and not $self->{"no_ucfirst"} 14 0 14
Condition33%1/3
ref $rstr and not $self->{"no_ucfirst"}
!ll&&!rl&&r
0014
MC/DC0%0/2
ref $rstr and not $self->{"no_ucfirst"}
ref $rstr not $self->{"no_ucfirst"}
Truth table33%1/3
A and not(B)
A= ref $rstrB= not $self->{"no_ucfirst"}
ABresult
0X0
100
111
69 }
70 77 my $stamp = &{$self->{stampfmt}};
71 return
72 77 ▶ ($stamp eq '' ? '' : "$stamp ") .
Branch: 2 branches
BranchTrueFalseTotal
$stamp eq '' ? : 0 77 77
$prefix eq '' ? : 14 63 77
73 ($prefix eq '' ? '' : "$prefix: ");
74 }
75  
76 8 1; # for require
« Agent/Driver/File.pm ↑ Summary Agent/Driver/Datum.pm »