| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | if ( exists $self->{ text } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition100%6/6
ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"} and exists $self->{"data"}{"appender"}
ref $self->{"data"} eq "HASH" and exists $self->{"data"}{"category"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 46 | my $ref = shift @todo; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 46 | for ( keys %$ref ) { | |||||||||||||||||||||||||||||||||||||||||
| 56 | 110 | ▶ | if ( ref( $ref->{ $_ } ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||