Skip to content

Commit 68bebae

Browse files
author
Eugene Ponizovsky
committed
Data::Rmap replaced by own function.
Data::Rmap has wrong behavior in my case on perl 5.18.0 and higher.
1 parent ade7c62 commit 68bebae

File tree

19 files changed

+136
-36
lines changed

19 files changed

+136
-36
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ nytprof.out
1212
.lwpcookies
1313
Makefile
1414
Makefile.old
15-
MANIFEST
1615
MANIFEST.bak
1716
MANIFEST.skip
1817
pm_to_blib

Changes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ Revision history for Perl extension Config::Processor.
22

33
0.02 Wed Apr 27 11:55:00 MSK 2016
44
- Initial release.
5-

MANIFEST

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Changes
2+
examples/etc/db.json
3+
examples/etc/db_connectors/default.yml
4+
examples/etc/db_connectors/default_test.yml
5+
examples/etc/dirs.yml
6+
examples/example.pl
7+
lib/Config/Processor.pm
8+
Makefile.PL
9+
MANIFEST This list of files
10+
README
11+
t/00-base.t
12+
t/01-accessors.t
13+
t/02-processing.t
14+
t/03-exceptions.t
15+
t/04-pod-coverage.t
16+
t/etc/bar_A.json
17+
t/etc/bar_B.jsn
18+
t/etc/foo_A.yaml
19+
t/etc/foo_B.yml
20+
t/etc/includes/moo_A.yml
21+
t/etc/includes/moo_B.json
22+
t/etc/includes/moo_C.yml
23+
t/etc/invalid.json
24+
t/etc/invalid.yml
25+
t/etc/jar.json
26+
t/etc/moo.yml
27+
t/etc/yar.yml
28+
t/etc/yar_A.yml
29+
t/etc/yar_B.yml
30+
t/etc/yar_C.yml
31+
t/etc/zoo.yml

Makefile.PL

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ WriteMakefile(
99
'YAML::XS' => '0.62',
1010
'Cpanel::JSON::XS' => '3.0213',
1111
'Hash::Merge' => '0.200',
12-
'Data::Rmap' => '0.64',
1312
'Carp' => '0',
1413
},
1514
CONFIGURE_REQUIRES => {

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Config-Processor version 0.01_01
1+
Config-Processor version 0.03_01
22
========================
33

44
INSTALLATION

examples/etc/db_connectors/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ default:
55
PrintWarn: 0
66
PrintError: 0
77
RaiseError: 1
8+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
default_test:
22
underlay: { var: myapp.db.connectors.default }
33
host: 'stat-test.mydb.com'
4+

examples/etc/dirs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ myapp:
99
- "${myapp.dirs.root_dir}/medis/${myapp.media_formats.0}"
1010
- "${myapp.dirs.root_dir}/media/${myapp.media_formats.1}"
1111
- "${myapp.dirs.root_dir}/media/${myapp.media_formats.2}"
12+

examples/example.pl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
);
1212

1313
# Load all configuration sections
14-
my $config = $config_processor->load( qw( dirs.yml db.json ),
14+
my $config = $config_processor->load(
15+
qw( dirs.yml db.json ),
16+
1517
{ myapp => {
1618
db => {
1719
connectors => {

lib/Config/Processor.pm

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ use 5.008000;
44
use strict;
55
use warnings;
66

7-
our $VERSION = '0.02';
7+
our $VERSION = '0.03_01';
88

99
use File::Spec;
1010
use YAML::XS qw( LoadFile );
1111
use Cpanel::JSON::XS;
1212
use Hash::Merge;
13-
use Data::Rmap qw( rmap_to :types );
1413
use Carp qw( croak );
1514

1615
my %FILE_EXTENSIONS_MAP = (
@@ -81,11 +80,8 @@ sub load {
8180
my $self = shift;
8281
my @config_sections = @_;
8382

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} );
8985

9086
$self->{_vars} = {};
9187

@@ -182,13 +178,36 @@ sub _load_json_file {
182178
return @data;
183179
}
184180

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+
185200
sub _process_node {
186201
my $self = shift;
187202
my $node = shift;
188203

189204
return unless defined $node;
190205

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} ) {
192211
if ( defined $node->{var} ) {
193212
$node = $self->_resolve_var( $node->{var} );
194213
}
@@ -209,10 +228,6 @@ sub _process_node {
209228
}
210229
}
211230
}
212-
elsif ( $self->{interpolate_variables} ) { # SCALAR
213-
$node =~ s/\$((\$?)\{([^\}]*)\})/
214-
$2 ? $1 : $self->_resolve_var( $3 )/ge;
215-
}
216231

217232
return $node;
218233
}
@@ -312,7 +327,9 @@ features
312327
dirs => [ qw( /etc/myapp /home/username/etc/myapp ) ],
313328
);
314329
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+
316333
{ myapp => {
317334
db => {
318335
connectors => {
@@ -339,7 +356,7 @@ F<.yaml>, F<.jsn>, F<.json>.
339356
=head2 new( %params )
340357
341358
my $config_processor = Config::Processor->new(
342-
dirs => [ qw( /etc/myapp /home/username/myapp/etc ) ],
359+
dirs => [ qw( /etc/myapp /home/username/etc/myapp ) ],
343360
);
344361
345362
$config_processor = Config::Processor->new(
@@ -368,9 +385,6 @@ Enables or disables directive processing. Enabled by default.
368385
369386
=head2 load( @config_sections )
370387
371-
my $config = $config_processor->load( qw( dirs.yml db.json metrics/* ),
372-
\%local_config );
373-
374388
Attempts to load all configuration sections and returns reference to resulting
375389
configuration tree.
376390

0 commit comments

Comments
 (0)