| 1 | package App::Environ::Config; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 4 | ▶ | use 5.008000; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 6 | |||||||||||||||||||
| 7 | 4 | our $VERSION = '0.22'; | |||||||||||||||||
| 8 | |||||||||||||||||||
| 9 | 4 | ▶ | use App::Environ; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | 4 | ▶ | use Config::Processor; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 4 | ▶ | use Carp qw( croak ); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 4 | my @REGD_CONFIG_SECTIONS; | |||||||||||||||||
| 14 | my %CONFIG_SECTIONS_IDX; | ||||||||||||||||||
| 15 | 4 | my $CONFIG; | |||||||||||||||||
| 16 | 4 | my $NEED_CONFIG_INIT = 1; | |||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | App::Environ->register( __PACKAGE__, | ||||||||||||||||||
| 19 | 1 | ▶ | initialize => sub { __PACKAGE__->_initialize(@_) }, | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 20 | 2 | ▶ | reload => sub { __PACKAGE__->_reload(@_) }, | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 21 | 1 | ▶ | 'finalize:r' => sub { __PACKAGE__->_finalize(@_) }, | ||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 22 | 4 | ); | |||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | |||||||||||||||||||
| 25 | 2 | ▶ | sub register { | ||||||||||||||||
|
Subroutine
register: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||
| 26 | 2 | my $class = shift; | |||||||||||||||||
| 27 | 2 | my @config_sections = @_; | |||||||||||||||||
| 28 | |||||||||||||||||||
| 29 | 2 | foreach my $config_section (@config_sections) { | |||||||||||||||||
| 30 | 2 | ▶ | next if exists $CONFIG_SECTIONS_IDX{$config_section}; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 31 | |||||||||||||||||||
| 32 | 2 | $CONFIG_SECTIONS_IDX{$config_section} = 1; | |||||||||||||||||
| 33 | 2 | push( @REGD_CONFIG_SECTIONS, $config_section ); | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 2 | $NEED_CONFIG_INIT = 1; | |||||||||||||||||
| 36 | } | ||||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | 2 | return; | |||||||||||||||||
| 39 | } | ||||||||||||||||||
| 40 | |||||||||||||||||||
| 41 | 5 | ▶ | sub instance { | ||||||||||||||||
|
Subroutine
instance: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 42 | 5 | ▶ | unless ( defined $CONFIG ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 43 | 1 | croak __PACKAGE__ . ' must be initialized first'; | |||||||||||||||||
| 44 | } | ||||||||||||||||||
| 45 | |||||||||||||||||||
| 46 | 4 | return $CONFIG; | |||||||||||||||||
| 47 | } | ||||||||||||||||||
| 48 | |||||||||||||||||||
| 49 | 1 | ▶ | sub _initialize { | ||||||||||||||||
|
Subroutine
_initialize: called CC=2 SCAR=7.0
| |||||||||||||||||||
| 50 | 1 | my $class = shift; | |||||||||||||||||
| 51 | |||||||||||||||||||
| 52 | 1 | ▶ | return unless $NEED_CONFIG_INIT; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | 1 | $class->_load; | |||||||||||||||||
| 55 | 1 | undef $NEED_CONFIG_INIT; | |||||||||||||||||
| 56 | |||||||||||||||||||
| 57 | 1 | return; | |||||||||||||||||
| 58 | } | ||||||||||||||||||
| 59 | |||||||||||||||||||
| 60 | 2 | ▶ | sub _reload { | ||||||||||||||||
|
Subroutine
_reload: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 61 | 2 | my $class = shift; | |||||||||||||||||
| 62 | |||||||||||||||||||
| 63 | 2 | $class->_load; | |||||||||||||||||
| 64 | |||||||||||||||||||
| 65 | 2 | return; | |||||||||||||||||
| 66 | } | ||||||||||||||||||
| 67 | |||||||||||||||||||
| 68 | 1 | ▶ | sub _finalize { | ||||||||||||||||
|
Subroutine
_finalize: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 69 | 1 | undef $CONFIG; | |||||||||||||||||
| 70 | 1 | $NEED_CONFIG_INIT = 1; | |||||||||||||||||
| 71 | |||||||||||||||||||
| 72 | 1 | return; | |||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | 3 | ▶ | sub _load { | ||||||||||||||||
|
Subroutine
_load: called CC=5 SCAR=16.7
| |||||||||||||||||||
| 76 | 3 | my @config_dirs; | |||||||||||||||||
| 77 | 3 | ▶ | if ( defined $ENV{APPCONF_DIRS} ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 78 | 3 | @config_dirs = split /:/, $ENV{APPCONF_DIRS}; | |||||||||||||||||
| 79 | } | ||||||||||||||||||
| 80 | 3 | my $interpolate_vars = $ENV{APPCONF_INTERPOLATE_VARIABLES}; | |||||||||||||||||
| 81 | 3 | my $process_directives = $ENV{APPCONF_PROCESS_DIRECTIVES}; | |||||||||||||||||
| 82 | 3 | my $export_env = $ENV{APPCONF_EXPORT_ENV}; | |||||||||||||||||
| 83 | |||||||||||||||||||
| 84 | 3 | ▶ | my $config_processor = Config::Processor->new( | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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 | $CONFIG = $config_processor->load(@REGD_CONFIG_SECTIONS); | |||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | 3 | return; | |||||||||||||||||
| 94 | } | ||||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | 4 | 1; | |||||||||||||||||
| 97 | __END__ | ||||||||||||||||||