line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Email::Blaster::ConfigLoader; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
59
|
|
5
|
2
|
|
|
2
|
|
9
|
use warnings 'all'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
6
|
2
|
|
|
2
|
|
1373
|
use XML::Simple (); |
|
2
|
|
|
|
|
15364
|
|
|
2
|
|
|
|
|
78
|
|
7
|
|
|
|
|
|
|
$XML::Simple::PREFERRED_PARSER = 'XML::Parser'; |
8
|
2
|
|
|
2
|
|
1146
|
use Email::Blaster::Config; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
58
|
|
9
|
2
|
|
|
2
|
|
12
|
use Cwd 'cwd'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
330
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $CONFIGFILE = 'email-blaster-config.xml'; |
12
|
|
|
|
|
|
|
our $Configs = { }; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#============================================================================== |
15
|
|
|
|
|
|
|
sub load |
16
|
|
|
|
|
|
|
{ |
17
|
2
|
|
|
2
|
0
|
6
|
my ($s) = @_; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
|
|
10
|
my $path = $s->config_path; |
20
|
2
|
50
|
|
|
|
95
|
return $Configs->{$path} if $Configs->{$path}; |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
47
|
my $xml = XML::Simple::XMLin( $path, |
23
|
|
|
|
|
|
|
ForceArray => [qw/ throttle handler lib server /], |
24
|
|
|
|
|
|
|
SuppressEmpty => '', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
0
|
(my $where = $path) =~ s/\/conf\/[^\/]+$//; |
28
|
0
|
|
|
|
|
0
|
my $doc = Email::Blaster::Config->new( $xml, $where ); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
0
|
return $Configs->{$path} = $doc; |
31
|
|
|
|
|
|
|
}# end parse() |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#============================================================================== |
34
|
|
|
|
|
|
|
sub config_path |
35
|
|
|
|
|
|
|
{ |
36
|
2
|
|
|
2
|
0
|
8
|
my $path = $CONFIGFILE; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
33
|
|
|
5744
|
my $root = $ENV{DOCUMENT_ROOT} || cwd(); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Try test dir: |
41
|
2
|
50
|
|
|
|
264
|
if( -f "$root/t/conf/$CONFIGFILE" ) |
42
|
|
|
|
|
|
|
{ |
43
|
2
|
|
|
|
|
30
|
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
|
0
|
|
|
|
|
return $path if -f $path; |
51
|
0
|
0
|
|
|
|
|
$root =~ s/\/[^\/]+$// |
52
|
|
|
|
|
|
|
or last; |
53
|
|
|
|
|
|
|
}# end for() |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
die "CANNOT FIND '$CONFIGFILE'"; |
56
|
|
|
|
|
|
|
}# end config_path() |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1;# return true: |
59
|
|
|
|
|
|
|
|