Configurator/AppConfig.pm

filter: Statementstmt 100% 48 / 48 Branchbran 90.0% 9 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 5 totaltotal 89.8% 71 / 79 CC 7 SCAR 8.8
CC
7
Cov
97%
new
4.0
parse_file
4.0
BEGIN
1.0
CRAP 2.4
« Config.pm ↑ Summary Configurator.pm »
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
BranchTrueFalseTotal
$section ? : 1 13 14
14 14 ▶ if(ref $file && $file->isa('AppConfig')){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file and $file->isa('AppConfig')) { } 1 13 14
Condition66%2/3
ref $file and $file->isa("AppConfig")
!ll&&!rl&&r
1301
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")
ABresult
0X0
100
111
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
BranchTrueFalseTotal
if ($self->{'config'}) { } 1 16 17
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
BranchTrueFalseTotal
unless $config->varlist("^${section}dispatchers\$") 1 16 17
41 17 ▶ $config->define("${section}format" => { DEFAULT => undef }) unless $config->varlist("^${section}format\$");
Branch: 1 branch
BranchTrueFalseTotal
unless $config->varlist("^${section}format\$") 17 0 17
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__
« Config.pm ↑ Summary Configurator.pm »