| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Environ::Config; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 3215 | use 5.008000; | 
|  | 3 |  |  |  |  | 7 |  | 
| 4 | 3 |  |  | 3 |  | 9 | use strict; | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 43 |  | 
| 5 | 3 |  |  | 3 |  | 9 | use warnings; | 
|  | 3 |  |  |  |  | 2 |  | 
|  | 3 |  |  |  |  | 99 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.20'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 3 |  |  | 3 |  | 9 | use App::Environ; | 
|  | 3 |  |  |  |  | 3 |  | 
|  | 3 |  |  |  |  | 41 |  | 
| 10 | 3 |  |  | 3 |  | 1264 | use Config::Processor; | 
|  | 3 |  |  |  |  | 32730 |  | 
|  | 3 |  |  |  |  | 82 |  | 
| 11 | 3 |  |  | 3 |  | 16 | use Carp qw( croak ); | 
|  | 3 |  |  |  |  | 3 |  | 
|  | 3 |  |  |  |  | 978 |  | 
| 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 | 880 | my $class = shift; | 
| 27 | 2 |  |  |  |  | 4 | my @config_sections = @_; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 2 |  |  |  |  | 3 | foreach my $config_section (@config_sections) { | 
| 30 | 2 | 50 |  |  |  | 4 | next if exists $CONFIG_SECTIONS_IDX{$config_section}; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 2 |  |  |  |  | 3 | $CONFIG_SECTIONS_IDX{$config_section} = 1; | 
| 33 | 2 |  |  |  |  | 2 | push( @REGD_CONFIG_SECTIONS, $config_section ); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 2 |  |  |  |  | 3 | $NEED_CONFIG_INIT = 1; | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 | 2 |  |  |  |  | 3 | return; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | sub instance { | 
| 42 | 5 | 100 |  | 5 | 1 | 348 | unless ( defined $CONFIG ) { | 
| 43 | 1 |  |  |  |  | 68 | croak __PACKAGE__ . ' must be initialized first'; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 4 |  |  |  |  | 7 | return $CONFIG; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | sub _initialize { | 
| 50 | 1 |  |  | 1 |  | 1 | my $class = shift; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 1 | 50 |  |  |  | 3 | return unless $NEED_CONFIG_INIT; | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  |  |  | 3 | $class->_load; | 
| 55 | 1 |  |  |  |  | 1 | undef $NEED_CONFIG_INIT; | 
| 56 |  |  |  |  |  |  |  | 
| 57 | 1 |  |  |  |  | 3 | return; | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub _reload { | 
| 61 | 2 |  |  | 2 |  | 1 | my $class = shift; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 2 |  |  |  |  | 3 | $class->_load; | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 2 |  |  |  |  | 6 | return; | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | sub _finalize { | 
| 69 | 1 |  |  | 1 |  | 4 | undef $CONFIG; | 
| 70 | 1 |  |  |  |  | 2 | $NEED_CONFIG_INIT = 1; | 
| 71 |  |  |  |  |  |  |  | 
| 72 | 1 |  |  |  |  | 3 | return; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | sub _load { | 
| 76 | 3 |  |  | 3 |  | 3 | my @config_dirs; | 
| 77 | 3 | 50 |  |  |  | 7 | if ( defined $ENV{APPCONF_DIRS} ) { | 
| 78 | 3 |  |  |  |  | 7 | @config_dirs = split /:/, $ENV{APPCONF_DIRS}; | 
| 79 |  |  |  |  |  |  | } | 
| 80 | 3 |  |  |  |  | 2 | my $interpolate_vars   = $ENV{APPCONF_INTERPOLATE_VARIABLES}; | 
| 81 | 3 |  |  |  |  | 4 | my $process_directives = $ENV{APPCONF_PROCESS_DIRECTIVES}; | 
| 82 | 3 |  |  |  |  | 2 | my $export_env         = $ENV{APPCONF_EXPORT_ENV}; | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 3 | 50 |  |  |  | 22 | 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 |  |  |  |  | 86 | $CONFIG = $config_processor->load(@REGD_CONFIG_SECTIONS); | 
| 92 |  |  |  |  |  |  |  | 
| 93 | 3 |  |  |  |  | 1324 | return; | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | 1; | 
| 97 |  |  |  |  |  |  | __END__ |