Log4perl/Config/PropertyConfigurator.pm

filter: Statementstmt 100% 79 / 79 Branchbran 89.2% 25 / 28 Conditioncond 77.7% 14 / 18 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 91.4% 129 / 141 CC 22 SCAR 25.8
CC
22
Cov
94%
parse
18.1
value
5.0
BEGIN
1.0
CRAP 13.2
« Log4perl/Appender/ScreenColoredLevels.pm ↑ Summary Log4perl/DateFormat.pm »
1 package Log::Log4perl::Config::PropertyConfigurator;
2 54 ▶use Log::Log4perl::Config::BaseConfigurator;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 54 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 54 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 54 our @ISA = qw(Log::Log4perl::Config::BaseConfigurator);
8  
9 54 our %NOT_A_MULT_VALUE = map { $_ => 1 }
10 qw(conversionpattern);
11  
12 #poor man's export
13 54 *eval_if_perl = \&Log::Log4perl::Config::eval_if_perl;
14 54 *compile_if_perl = \&Log::Log4perl::Config::compile_if_perl;
15 54 *unlog4j = \&Log::Log4perl::Config::unlog4j;
16  
17 54 ▶use constant _INTERNAL_DEBUG => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 54 our $COMMENT_REGEX = qr/[#;!]/;
20  
21 ################################################
22 153 ▶sub parse {
Subroutine parse: called CC=18 SCAR=29.0
Pod documented
23 ################################################
24 153 my($self, $newtext) = @_;
25  
26 153 ▶ $self->text($newtext) if defined $newtext;
Branch: 1 branch
BranchTrueFalseTotal
if defined $newtext 151 2 153
27  
28 153 my $text = $self->{text};
29  
30 153 ▶ die "Config parser has nothing to parse" unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 153 153
31  
32 153 my $data = {};
33 153 my %var_subst = ();
34  
35 153 ▶ while (@$text) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$text) 1203 150 1353
36 1203 local $_ = shift @$text;
37 1203 s/^\s*$COMMENT_REGEX.*//;
38 1203 ▶ next unless /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\S/ 302 901 1203
39
40 901 my @parts = ();
41  
42 901 ▶ while (/(.+?)\\\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.+?)\\\s*$/) 47 901 948
43 47 my $prev = $1;
44 47 my $next = shift(@$text);
45 47 $next =~ s/^ +//g; #leading spaces
46 47 $next =~ s/^$COMMENT_REGEX.*//;
47 47 $_ = $prev. $next;
48 47 chomp;
49 }
50  
51 901 ▶ if(my($key, $val) = /(\S+?)\s*=\s*(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = /(\S+?)\s*=\s*(.*)/) 901 0 901
52  
53 901 my $key_org = $key;
54  
55 901 $val =~ s/\s+$//;
56  
57 # Everything could potentially be a variable assignment
58 901 $var_subst{$key} = $val;
59  
60 # Substitute any variables
61 901 $val =~ s/\$\{(.*?)\}/
62 14 Log::Log4perl::Config::var_subst($1, \%var_subst)/gex;
63  
64 900 $key = unlog4j($key);
65  
66 900 my $how_deep = 0;
67 900 my $ptr = $data;
68 900 for my $part (split /\.|::/, $key) {
69 2340 push @parts, $part;
70 2340 ▶ $ptr->{$part} = {} unless exists $ptr->{$part};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $ptr->{$part} 1182 1158 2340
71 2340 $ptr = $ptr->{$part};
72 2340 ++$how_deep;
73 }
74  
75 #here's where we deal with turning multiple values like this:
76 # log4j.appender.jabbender.to = him@a.jabber.server
77 # log4j.appender.jabbender.to = her@a.jabber.server
78 #into an arrayref like this:
79 #to => { value =>
80 # ["him\@a.jabber.server", "her\@a.jabber.server"] },
81 #
82 # This only is allowed for properties of appenders
83 # not listed in %NOT_A_MULT_VALUE (see top of file).
84 900 ▶ if (exists $ptr->{value} &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ptr->{'value'} and $how_deep > 2 and defined $parts[0] and lc $parts[0] eq 'appender' and defined $parts[2] and not exists $Log::Log4perl::Config::PropertyConfigurator::NOT_A_MULT_VALUE{lc $parts[2]}) { } 1 899 900
Condition80%12/15
exists $ptr->{"value"} and $how_deep > 2 and defined $parts[0] and lc $parts[0] eq "appender" and defined $parts[2] and not exists $Log::Log4perl::Config::PropertyConfigurator::NOT_A_MULT_VALUE{lc $parts[2]}
!ll&&!rl&&r
89901
exists $ptr->{"value"} and $how_deep > 2 and defined $parts[0] and lc $parts[0] eq "appender" and defined $parts[2]
!ll&&!rl&&r
89901
exists $ptr->{"value"} and $how_deep > 2 and defined $parts[0] and lc $parts[0] eq "appender"
!ll&&!rl&&r
89811
exists $ptr->{"value"} and $how_deep > 2 and defined $parts[0]
!ll&&!rl&&r
89802
exists $ptr->{"value"} and $how_deep > 2
!ll&&!rl&&r
89622
MC/DC50%3/6
exists $ptr->{"value"} and $how_deep > 2 and defined $parts[0] and lc $parts[0] eq "appender" and defined $parts[2] and not exists $Log::Log4perl::Config::PropertyConfigurator::NOT_A_MULT_VALUE{lc $parts[2]}
exists $ptr->{"value"} $how_deep > 2 defined $parts[0] lc $parts[0] eq "appender" defined $parts[2] not exists $Log::Log4perl::Config::PropertyConfigurator::NOT_A_MULT_VALUE{lc $parts[2]}
Truth table57%4/7
A and B and C and D and E and not(F)
A= exists $ptr->{"value"}B= $how_deep > 2C= defined $parts[0]D= lc $parts[0] eq "appender"E= defined $parts[2]F= not exists $Log::Log4perl::Config::PropertyConfigurator::NOT_A_MULT_VALUE{lc $parts[2]}
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
85 $how_deep > 2 &&
86 defined $parts[0] && lc($parts[0]) eq "appender" &&
87 defined $parts[2] && ! exists $NOT_A_MULT_VALUE{lc($parts[2])}
88 ) {
89 1 ▶ if (ref ($ptr->{value}) ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ptr->{"value"} ne "ARRAY") 1 0 1
90 1 my $temp = $ptr->{value};
91 1 $ptr->{value} = [];
92 1 push (@{$ptr->{value}}, $temp);
93 }
94 1 push (@{$ptr->{value}}, $val);
95 }else{
96 899 ▶ if(defined $ptr->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ptr->{"value"}) 3 896 899
97 3 ▶ if(! $Log::Log4perl::Logger::NO_STRICT) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Log::Log4perl::Logger::NO_STRICT) 2 1 3
98 2 die "$key_org redefined";
99 }
100 }
101 897 $ptr->{value} = $val;
102 }
103 }
104 }
105 150 $self->{data} = $data;
106 150 return $data;
107 }
108  
109 ################################################
110 4 ▶sub value {
Subroutine value: called CC=5 SCAR=16.1
Pod undocumented
111 ################################################
112 4 my($self, $path) = @_;
113  
114 4 $path = unlog4j($path);
115  
116 4 my @p = split /::/, $path;
117  
118 4 my $found = 0;
119 4 my $r = $self->{data};
120  
121 4 ▶ while (my $n = shift @p) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = shift @p) 8 4 12
122 8 ▶ if (exists $r->{$n}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $r->{$n}) { } 7 1 8
123 7 $r = $r->{$n};
124 7 $found = 1;
125 } else {
126 1 $found = 0;
127 }
128 }
129  
130 4 ▶ if($found and exists $r->{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found and exists $r->{'value'}) { } 3 1 4
Condition66%2/3
$found and exists $r->{"value"}
!ll&&!rl&&r
103
MC/DC50%1/2
$found and exists $r->{"value"}
$found exists $r->{"value"}
Truth table66%2/3
A and B
A= $foundB= exists $r->{"value"}
ABresult
0X0
100
111
131 3 return $r->{value};
132 } else {
133 1 return undef;
134 }
135 }
136  
137 54 1;
138  
139 __END__
« Log4perl/Appender/ScreenColoredLevels.pm ↑ Summary Log4perl/DateFormat.pm »