| 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
| |||||||||||||||||||||
| 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()
MC/DC0%0/2
$ENV{'DOCUMENT_ROOT'} || cwd()
$ENV{'DOCUMENT_ROOT'}
cwd()
Truth table33%1/3
A || B
A= $ENV{'DOCUMENT_ROOT'}B= cwd()
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Try test dir: | ||||||||||||||||||||
| 41 | 2 | ▶ | if( -f "$root/t/conf/$CONFIGFILE" ) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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
| |||||||||||||||||||||
| 51 | 0 | ▶ | $root =~ s/\/[^\/]+$// | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | or last; | ||||||||||||||||||||
| 53 | }# end for() | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 0 | die "CANNOT FIND '$CONFIGFILE'"; | |||||||||||||||||||
| 56 | }# end config_path() | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 2 | 1;# return true: | |||||||||||||||||||
| 59 | |||||||||||||||||||||