@@ -4,13 +4,12 @@ use 5.008000;
4
4
use strict;
5
5
use warnings;
6
6
7
- our $VERSION = ' 0.02 ' ;
7
+ our $VERSION = ' 0.03_01 ' ;
8
8
9
9
use File::Spec;
10
10
use YAML::XS qw( LoadFile ) ;
11
11
use Cpanel::JSON::XS;
12
12
use Hash::Merge;
13
- use Data::Rmap qw( rmap_to :types ) ;
14
13
use Carp qw( croak ) ;
15
14
16
15
my %FILE_EXTENSIONS_MAP = (
@@ -81,11 +80,8 @@ sub load {
81
80
my $self = shift ;
82
81
my @config_sections = @_ ;
83
82
84
- $self -> {_config } = $self -> _build_tree( @config_sections );
85
-
86
- rmap_to {
87
- $_ = $self -> _process_node( $_ );
88
- } HASH|VALUE, $self -> {_config };
83
+ $self -> {_config } = $self -> _build_tree(@config_sections );
84
+ $self -> _process_tree( $self -> {_config } );
89
85
90
86
$self -> {_vars } = {};
91
87
@@ -182,13 +178,36 @@ sub _load_json_file {
182
178
return @data ;
183
179
}
184
180
181
+ sub _process_tree {
182
+ my $self = shift ;
183
+
184
+ $_ [0] = $self -> _process_node( $_ [0] );
185
+
186
+ if ( ref ( $_ [0] ) eq ' HASH' ) {
187
+ foreach ( values %{ $_ [0] } ) {
188
+ $self -> _process_tree($_ );
189
+ }
190
+ }
191
+ elsif ( ref ( $_ [0] ) eq ' ARRAY' ) {
192
+ foreach ( @{ $_ [0] } ) {
193
+ $self -> _process_tree($_ );
194
+ }
195
+ }
196
+
197
+ return ;
198
+ }
199
+
185
200
sub _process_node {
186
201
my $self = shift ;
187
202
my $node = shift ;
188
203
189
204
return unless defined $node ;
190
205
191
- if ( ref ($node ) eq ' HASH' && $self -> {process_directives } ) {
206
+ if ( !ref ($node ) && $self -> {interpolate_variables } ) {
207
+ $node =~ s /\$ ((\$ ?)\{ ([^\} ]*)\} )/
208
+ $2 ? $1 : $self ->_resolve_var( $3 )/ ge ;
209
+ }
210
+ elsif ( ref ($node ) eq ' HASH' && $self -> {process_directives } ) {
192
211
if ( defined $node -> {var } ) {
193
212
$node = $self -> _resolve_var( $node -> {var } );
194
213
}
@@ -209,10 +228,6 @@ sub _process_node {
209
228
}
210
229
}
211
230
}
212
- elsif ( $self -> {interpolate_variables } ) { # SCALAR
213
- $node =~ s /\$ ((\$ ?)\{ ([^\} ]*)\} )/
214
- $2 ? $1 : $self ->_resolve_var( $3 )/ ge ;
215
- }
216
231
217
232
return $node ;
218
233
}
@@ -312,7 +327,9 @@ features
312
327
dirs => [ qw( /etc/myapp /home/username/etc/myapp ) ],
313
328
);
314
329
315
- my $config = $config_processor->load( qw( dirs.yml db.json metrics/* ),
330
+ my $config = $config_processor->load(
331
+ qw( dirs.yml db.json metrics/* ),
332
+
316
333
{ myapp => {
317
334
db => {
318
335
connectors => {
@@ -339,7 +356,7 @@ F<.yaml>, F<.jsn>, F<.json>.
339
356
=head2 new( %params )
340
357
341
358
my $config_processor = Config::Processor->new(
342
- dirs => [ qw( /etc/myapp /home/username/myapp/ etc ) ],
359
+ dirs => [ qw( /etc/myapp /home/username/etc/myapp ) ],
343
360
);
344
361
345
362
$config_processor = Config::Processor->new(
@@ -368,9 +385,6 @@ Enables or disables directive processing. Enabled by default.
368
385
369
386
=head2 load( @config_sections )
370
387
371
- my $config = $config_processor->load( qw( dirs.yml db.json metrics/* ),
372
- \%local_config );
373
-
374
388
Attempts to load all configuration sections and returns reference to resulting
375
389
configuration tree.
376
390
0 commit comments