lib/Email/Blaster/ConfigLoader.pm

filter: Statementstmt 77.1% 27 / 35 Branchbran 25.0% 2 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 2 totaltotal 64.9% 37 / 57 CC 7 SCAR 21.3
CC
7
Cov
65%
config_path
16.7
load
2.4
BEGIN
1.0
CRAP 8.4
« lib/Email/Blaster/ConfigNode.pm ↑ Summary lib/Email/Blaster/Config.pm »
1  
2 package Email::Blaster::ConfigLoader;
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use XML::Simple ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 $XML::Simple::PREFERRED_PARSER = 'XML::Parser';
8 2 ▶use Email::Blaster::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Cwd 'cwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $CONFIGFILE = 'email-blaster-config.xml';
12 2 our $Configs = { };
13  
14 #==============================================================================
15 sub load
16 2 ▶{
Subroutine load: called CC=2 SCAR=8.5
Pod undocumented
17 2 my ($s) = @_;
18
19 2 my $path = $s->config_path;
20 2 ▶ return $Configs->{$path} if $Configs->{$path};
Branch: 1 branch
BranchTrueFalseTotal
if $Email::Blaster::ConfigLoader::Configs->{$path} 0 2 2
21
22 2 my $xml = XML::Simple::XMLin( $path,
23 ForceArray => [qw/ throttle handler lib server /],
24 SuppressEmpty => '',
25 );
26
27 0 (my $where = $path) =~ s/\/conf\/[^\/]+$//;
28 0 my $doc = Email::Blaster::Config->new( $xml, $where );
29
30 0 return $Configs->{$path} = $doc;
31 }# end parse()
32  
33 #==============================================================================
34 sub config_path
35 2 ▶{
Subroutine config_path: called CC=6 SCAR=28.1
Pod undocumented
36 2 my $path = $CONFIGFILE;
37
38 2 ▶ my $root = $ENV{DOCUMENT_ROOT} || cwd();
Condition33%1/3
$ENV{'DOCUMENT_ROOT'} || cwd()
l!l&&r!l&&!r
020
MC/DC0%0/2
$ENV{'DOCUMENT_ROOT'} || cwd()
$ENV{'DOCUMENT_ROOT'} cwd()
Truth table33%1/3
A || B
A= $ENV{'DOCUMENT_ROOT'}B= cwd()
ABresult
1X1
011
000
39
40 # Try test dir:
41 2 ▶ if( -f "$root/t/conf/$CONFIGFILE" )
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$root/t/conf/$Email::Blaster::ConfigLoader::CONFIGFILE") 2 0 2
42 {
43 2 return "$root/t/conf/$CONFIGFILE";
44 }# end if()
45
46 # Start moving up:
47 0 for( 1...10 )
48 {
49 0 my $path = "$root/conf/$CONFIGFILE";
50 0 ▶ return $path if -f $path;
Branch: 1 branch
BranchTrueFalseTotal
if -f $path 0 0 0
51 0 ▶ $root =~ s/\/[^\/]+$//
Branch: 1 branch
BranchTrueFalseTotal
$root =~ s[/[^/]+$][] or last 0 0 0
52 or last;
53 }# end for()
54
55 0 die "CANNOT FIND '$CONFIGFILE'";
56 }# end config_path()
57  
58 2 1;# return true:
59  
« lib/Email/Blaster/ConfigNode.pm ↑ Summary lib/Email/Blaster/Config.pm »