blib/lib/Log/Log4perl/Config/YamlConfigurator.pm

filter: Statementstmt 100% 47 / 47 Branchbran 92.8% 13 / 14 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 3 / 3 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 98.7% 81 / 82 CC 11 SCAR 13.2
CC
11
Cov
99%
new
6.0
parse
5.0
create_appender_instance
2.0
CRAP 3.7
↑ Summary
1 # Prefer numeric version for backwards compatibility
2 3 ▶BEGIN { require 5.006000 }; ## no critic ( RequireUseStrict, RequireUseWarnings )
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Log::Log4perl::Config::YamlConfigurator;
7  
8 3 $Log::Log4perl::Config::YamlConfigurator::VERSION = 'v1.2.0';
9  
10 3 ▶use parent qw( Clone Log::Log4perl::Config::BaseConfigurator );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Log::Log4perl::Config ();
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶sub create_appender_instance {
Subroutine create_appender_instance: called CC=2 SCAR=7.1
Pod documented
16 2 my ( $self, $name ) = @_;
17  
18 2 my $data = $self->parse;
19 Log::Log4perl::Config::create_appender_instance( $data, $name, {}, [],
20 exists $data->{ threshold } ? $data->{ threshold }->{ value } : undef )
21 2 ▶}
Branch: 1 branch
BranchTrueFalseTotal
exists $data->{'threshold'} ? : 0 2 2
22  
23 6 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
24 6 my $class = shift;
25  
26 6 my $self = $class->SUPER::new( subst => {}, @_ );
27  
28 6 ▶ unless ( exists $self->{ data } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}) 3 3 6
29 3 ▶ if ( exists $self->{ text } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'text'}) { } 2 1 3
30 2 require YAML::PP;
31 2 $self->{ data } = YAML::PP::Load( join( "\n", @{ $self->{ text } } ) )
32 } else {
33 1 croak "'text' parameter not set, stopped"
34 }
35 }
36  
37 croak "'data' parameter has to be a HASH reference with the keys 'category', and 'appender', stopped"
38 unless ref( $self->{ data } ) eq 'HASH'
39 and exists $self->{ data }->{ category }
40 5 ▶ and exists $self->{ data }->{ appender };
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"} and exists $self->{"data"}{"appender"} 3 2 5
Condition100%6/6
ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"} and exists $self->{"data"}{"appender"}
!ll&&!rl&&r
212
ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"}
!ll&&!rl&&r
113
MC/DC100%3/3
ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"} and exists $self->{"data"}{"appender"}
ref $self->{"data"} eq "HASH" exists $self->{"data"}{"category"} exists $self->{"data"}{"appender"}
Truth table100%4/4
A and B and C
A= ref $self->{"data"} eq "HASH"B= exists $self->{"data"}{"category"}C= exists $self->{"data"}{"appender"}
ABCresult
0XX0
10X0
1100
1111
41  
42 2 $self
43 }
44  
45 # https://metacpan.org/pod/Log::Log4perl::Config::BaseConfigurator#Parser-requirements
46 4 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
47 4 my ( $self ) = @_;
48  
49 # Make sure that a parse() does not change $self!
50 4 my $copy = $self->clone;
51 4 my @todo = ( $copy->{ data } );
52  
53 4 ▶ while ( @todo ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@todo) 46 4 50
54 46 my $ref = shift @todo;
55 46 for ( keys %$ref ) {
56 110 ▶ if ( ref( $ref->{ $_ } ) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $ref->{$_} eq 'HASH') { } 42 68 110
elsif ($_ eq 'name') { } 22 46 68
57 42 push @todo, $ref->{ $_ }
58 } elsif ( $_ eq 'name' ) {
59 # Appender 'name' entries and layout 'name entries are converted to ->{ value } entries
60 22 ( $ref->{ value } = $ref->{ $_ } ) =~ s/\$\{(.*?)\}/Log::Log4perl::Config::var_subst( $1, $self->{ subst } )/ge;
61 22 delete $ref->{ $_ }
62 } else {
63 46 ( my $tmp = $ref->{ $_ } ) =~ s/\$\{(.*?)\}/Log::Log4perl::Config::var_subst( $1, $self->{ subst } )/ge;
64 46 $ref->{ $_ } = {};
65 46 $ref->{ $_ }->{ value } = $tmp
66 }
67 }
68 }
69  
70 $copy->{ data }
71 4 }
72  
73 3 1
↑ Summary