line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::Environ::Config; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
3239
|
use 5.008000; |
|
3
|
|
|
|
|
7
|
|
4
|
3
|
|
|
3
|
|
9
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
44
|
|
5
|
3
|
|
|
3
|
|
7
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
92
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.22'; |
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
10
|
use App::Environ; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
50
|
|
10
|
3
|
|
|
3
|
|
1327
|
use Config::Processor; |
|
3
|
|
|
|
|
34789
|
|
|
3
|
|
|
|
|
88
|
|
11
|
3
|
|
|
3
|
|
18
|
use Carp qw( croak ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1014
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my @REGD_CONFIG_SECTIONS; |
14
|
|
|
|
|
|
|
my %CONFIG_SECTIONS_IDX; |
15
|
|
|
|
|
|
|
my $CONFIG; |
16
|
|
|
|
|
|
|
my $NEED_CONFIG_INIT = 1; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
App::Environ->register( __PACKAGE__, |
19
|
|
|
|
|
|
|
initialize => sub { __PACKAGE__->_initialize(@_) }, |
20
|
|
|
|
|
|
|
reload => sub { __PACKAGE__->_reload(@_) }, |
21
|
|
|
|
|
|
|
'finalize:r' => sub { __PACKAGE__->_finalize(@_) }, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub register { |
26
|
2
|
|
|
2
|
1
|
1034
|
my $class = shift; |
27
|
2
|
|
|
|
|
4
|
my @config_sections = @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
3
|
foreach my $config_section (@config_sections) { |
30
|
2
|
50
|
|
|
|
6
|
next if exists $CONFIG_SECTIONS_IDX{$config_section}; |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
4
|
$CONFIG_SECTIONS_IDX{$config_section} = 1; |
33
|
2
|
|
|
|
|
2
|
push( @REGD_CONFIG_SECTIONS, $config_section ); |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
2
|
$NEED_CONFIG_INIT = 1; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
5
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub instance { |
42
|
5
|
100
|
|
5
|
1
|
466
|
unless ( defined $CONFIG ) { |
43
|
1
|
|
|
|
|
95
|
croak __PACKAGE__ . ' must be initialized first'; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
8
|
return $CONFIG; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub _initialize { |
50
|
1
|
|
|
1
|
|
2
|
my $class = shift; |
51
|
|
|
|
|
|
|
|
52
|
1
|
50
|
|
|
|
4
|
return unless $NEED_CONFIG_INIT; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
4
|
$class->_load; |
55
|
1
|
|
|
|
|
2
|
undef $NEED_CONFIG_INIT; |
56
|
|
|
|
|
|
|
|
57
|
1
|
|
|
|
|
2
|
return; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _reload { |
61
|
2
|
|
|
2
|
|
3
|
my $class = shift; |
62
|
|
|
|
|
|
|
|
63
|
2
|
|
|
|
|
4
|
$class->_load; |
64
|
|
|
|
|
|
|
|
65
|
2
|
|
|
|
|
5
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _finalize { |
69
|
1
|
|
|
1
|
|
4
|
undef $CONFIG; |
70
|
1
|
|
|
|
|
1
|
$NEED_CONFIG_INIT = 1; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
2
|
return; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _load { |
76
|
3
|
|
|
3
|
|
2
|
my @config_dirs; |
77
|
3
|
50
|
|
|
|
9
|
if ( defined $ENV{APPCONF_DIRS} ) { |
78
|
3
|
|
|
|
|
10
|
@config_dirs = split /:/, $ENV{APPCONF_DIRS}; |
79
|
|
|
|
|
|
|
} |
80
|
3
|
|
|
|
|
4
|
my $interpolate_vars = $ENV{APPCONF_INTERPOLATE_VARIABLES}; |
81
|
3
|
|
|
|
|
3
|
my $process_directives = $ENV{APPCONF_PROCESS_DIRECTIVES}; |
82
|
3
|
|
|
|
|
5
|
my $export_env = $ENV{APPCONF_EXPORT_ENV}; |
83
|
|
|
|
|
|
|
|
84
|
3
|
50
|
|
|
|
26
|
my $config_processor = Config::Processor->new( |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
85
|
|
|
|
|
|
|
dirs => \@config_dirs, |
86
|
|
|
|
|
|
|
$interpolate_vars ? ( interpolate_variables => $interpolate_vars ) : (), |
87
|
|
|
|
|
|
|
$process_directives ? ( process_directives => $process_directives ) : (), |
88
|
|
|
|
|
|
|
$export_env ? ( export_env => $export_env ) : (), |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
3
|
|
|
|
|
85
|
$CONFIG = $config_processor->load(@REGD_CONFIG_SECTIONS); |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
|
|
1338
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
__END__ |