| 1 | package Log::Dispatch::Configurator::AppConfig; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | $VERSION = '1.00'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Log::Dispatch::Configurator; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use base qw(Log::Dispatch::Configurator); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use AppConfig; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 14 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 14 | my($class, $file, $section) = @_; | |||||||||||||||||||||||||||
| 13 | 14 | ▶ | my $self = bless { section => ($section ? "${section}_" : '') }, $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 14 | ▶ | if(ref $file && $file->isa('AppConfig')){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $file and $file->isa("AppConfig")
MC/DC50%1/2
ref $file and $file->isa("AppConfig")
ref $file
$file->isa("AppConfig")
Truth table66%2/3
A and B
A= ref $fileB= $file->isa("AppConfig")
| |||||||||||||||||||||||||||||
| 15 | 1 | $self->{config} = $file; | |||||||||||||||||||||||||||
| 16 | }else{ | ||||||||||||||||||||||||||||
| 17 | 13 | $self->{file} = $file; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | 14 | $self->parse_file; | |||||||||||||||||||||||||||
| 20 | 14 | return $self; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 17 | ▶ | sub parse_file { | ||||||||||||||||||||||||||
|
Subroutine
parse_file: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 17 | my $section = $self->{section}; | |||||||||||||||||||||||||||
| 27 | 17 | my $config; | |||||||||||||||||||||||||||
| 28 | 17 | ▶ | if($self->{config}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 1 | $config = $self->{config}; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | else{ | ||||||||||||||||||||||||||||
| 32 | 16 | $config = AppConfig->new({ | |||||||||||||||||||||||||||
| 33 | CREATE => 1, | ||||||||||||||||||||||||||||
| 34 | GLOBAL => { | ||||||||||||||||||||||||||||
| 35 | ARGCOUNT => AppConfig::ARGCOUNT_ONE(), | ||||||||||||||||||||||||||||
| 36 | }, | ||||||||||||||||||||||||||||
| 37 | }); | ||||||||||||||||||||||||||||
| 38 | 16 | $config->file($self->{file}); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | 17 | ▶ | $config->define("${section}dispatchers" => { DEFAULT => '' }) unless $config->varlist("^${section}dispatchers\$"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 17 | ▶ | $config->define("${section}format" => { DEFAULT => undef }) unless $config->varlist("^${section}format\$"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 17 | $self->{_config} = $config; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | sub reload { | ||||||||||||||||||||||||||
|
Subroutine
reload: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 48 | 3 | $self->parse_file; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 60 | ▶ | sub _config { $_[0]->{_config} } | ||||||||||||||||||||||||||
|
Subroutine
_config: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 17 | ▶ | sub get_attrs_global { | ||||||||||||||||||||||||||
|
Subroutine
get_attrs_global: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 17 | my $section = $self->{section}; | |||||||||||||||||||||||||||
| 56 | return { | ||||||||||||||||||||||||||||
| 57 | 17 | format => scalar $self->_config->get("${section}format"), | |||||||||||||||||||||||||||
| 58 | dispatchers => [ split /\s+/, $self->_config->get("${section}dispatchers") ], | ||||||||||||||||||||||||||||
| 59 | }; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 26 | ▶ | sub get_attrs { | ||||||||||||||||||||||||||
|
Subroutine
get_attrs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 26 | my($self, $name) = @_; | |||||||||||||||||||||||||||
| 64 | 26 | my $section = $self->{section}; | |||||||||||||||||||||||||||
| 65 | 26 | my $regex = "^$section$name" . '[\._]'; | |||||||||||||||||||||||||||
| 66 | 26 | my %var = $self->_config->varlist($regex); | |||||||||||||||||||||||||||
| 67 | my %param = map { | ||||||||||||||||||||||||||||
| 68 | 26 | (my $key = $_) =~ s/$regex//; | |||||||||||||||||||||||||||
| 69 | 109 | $key => $var{$_}; | |||||||||||||||||||||||||||
| 70 | } keys %var; | ||||||||||||||||||||||||||||
| 71 | 26 | return \%param; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 13 | 1; | |||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||