Skip to content

Commit 6beaba6

Browse files
author
Eugene Ponizovsky
committed
Config::Loader renamed to Config::Processor
Also improoved unit tests and added a half of POD documentation.
1 parent f2df274 commit 6beaba6

21 files changed

+1236
-1154
lines changed

Changes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Revision history for Perl extension Config::Loader.
1+
Revision history for Perl extension Config::Processor.
22

33
0.01 Tue Apr 19 11:22:20 2016
44
- original version; created by h2xs 1.23 with options
5-
-AXO --skip-exporter --skip-autoloader -b5.8.0 -n Config::Loader
5+
-AXO --skip-exporter --skip-autoloader -b5.8.0 -n Config::Processor
66

Makefile.PL

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use 5.008000;
22
use ExtUtils::MakeMaker;
33

44
WriteMakefile(
5-
NAME => 'Config::Loader',
6-
VERSION_FROM => 'lib/Config/Loader.pm',
5+
NAME => 'Config::Processor',
6+
VERSION_FROM => 'lib/Config/Processor.pm',
77
PREREQ_PM => {
88
'File::Spec' => '0',
99
'YAML::XS' => '0.62',
@@ -21,13 +21,13 @@ WriteMakefile(
2121
},
2222
META_MERGE => {
2323
resources => {
24-
homepage => 'https://github.com/iph0/Config-Loader',
25-
bugtracker => 'https://github.com/iph0/Config-Loader/issues',
26-
repository => 'https://github.com/iph0/Config-Loader',
24+
homepage => 'https://github.com/iph0/Config-Processor',
25+
bugtracker => 'https://github.com/iph0/Config-Processor/issues',
26+
repository => 'https://github.com/iph0/Config-Processor',
2727
license => 'http://dev.perl.org/licenses/',
2828
},
2929
},
30-
ABSTRACT_FROM => 'lib/Config/Loader.pm',
30+
ABSTRACT_FROM => 'lib/Config/Processor.pm',
3131
AUTHOR => 'Eugene Ponizovsky <[email protected]>',
3232
LICENSE => 'perl',
3333
);

README

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Config-Loader version 0.01_01
1+
Config-Processor version 0.01_01
22
========================
33

44
INSTALLATION
@@ -12,7 +12,7 @@ To install this module type the following:
1212

1313
DESCRIPTION
1414

15-
Config::Loader is the cascading configuration files parser with file inclusions
15+
Config::Processor is the cascading configuration files parser with file inclusions
1616
and variables interpolation support.
1717

1818
AUTHOR

examples/example.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
use strict;
44
use warnings;
55

6-
use Config::Loader;
6+
use Config::Processor;
77
use Data::Dumper;
88

9-
my $config_loader = Config::Loader->new(
10-
dirs => [qw( examples/etc )],
9+
my $config_processor = Config::Processor->new(
10+
dirs => [ qw( examples/etc ) ],
1111
);
1212

1313
# Load all configuration sections
14-
my $config = $config_loader->load(
14+
my $config = $config_processor->load(
1515
qw( users.yml db.json passwords/* pathes.yml ),
1616

1717
{ db => {

lib/Config/Loader.pm renamed to lib/Config/Processor.pm

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package Config::Loader;
1+
package Config::Processor;
22

33
use 5.008000;
44
use strict;
@@ -299,22 +299,105 @@ __END__
299299
300300
=head1 NAME
301301
302-
Config::Loader - Cascading configuration files parser with file inclusions
302+
Config::Processor - Cascading configuration files processor with file inclusions
303303
and variables interpolation support
304304
305305
=head1 SYNOPSIS
306306
307307
=head1 DESCRIPTION
308308
309+
=head1 CONSTRUCTOR
310+
311+
=head2 new( %params )
312+
313+
my $config_processor = Config::Processor->new(
314+
dirs => [ qw( /etc/myapp /home/username/myapp/etc ) ],
315+
);
316+
317+
my $another_config_processor = Config::Processor->new(
318+
dirs => [ qw( /etc/myapp /home/username/myapp/etc ) ],
319+
interpolate_variables => 0,
320+
process_directives => 0,
321+
);
322+
323+
=over
324+
325+
=item dirs => \@dirs
326+
327+
List of directories in which configuration files will be serched.
328+
329+
=item interpolate_variables => $boolean
330+
331+
Enables or disables variable interpolation in configuration files.
332+
333+
Enabled by default.
334+
335+
=item process_directives => $boolean
336+
337+
Enables or disables directive processing in configuration files.
338+
339+
Enabled by default.
340+
341+
=back
342+
309343
=head1 METHODS
310344
311-
=head2 new()
345+
=head2 load( @config_sections )
312346
313-
=head2 load()
347+
my $config = $config_processor->load(
348+
qw( users.yml db.json passwords/* pathes.yml ),
314349
315-
=head2 interpolate_variables
350+
{ db => {
351+
frontend_master => {
352+
host => 'localhost',
353+
port => '5000',
354+
},
316355
317-
=head2 process_directives
356+
frontend_slave => {
357+
host => 'localhost',
358+
port => '5000',
359+
}
360+
},
361+
}
362+
);
363+
364+
Attempts to load all configuration sections and returns reference to resulting
365+
configuration tree.
366+
367+
Configuration section can be specified in three ways: as a relative filename,
368+
as a filename with wildcard characters or as a hash reference. Filenames with
369+
wildcard characters is processed by C<glob> function.
370+
371+
=head2 interpolate_variables( [ $boolean ] )
372+
373+
Enables or disables variable interpolation in configurations files.
374+
375+
=head2 process_directives( [ $boolean ] )
376+
377+
Enables or disables directive processing in configuration files.
378+
379+
=head1 MERGING RULES
380+
381+
Configuration parser merges all specified configuration sections in one
382+
resulting configuration tree by following rules:
383+
384+
Left value Right value Result value
385+
386+
SCALAR $a SCALAR $b SCALAR $b
387+
SCALAR $a ARRAY \@b ARRAY \@b
388+
SCALAR $a HASH \%b HASH \%b
389+
390+
ARRAY \@a SCALAR $b SCALAR $b
391+
ARRAY \@a ARRAY \@b ARRAY \@b
392+
ARRAY \@a HASH \%b HASH \%b
393+
394+
HASH \%a SCALAR $b SCALAR $b
395+
HASH \%a ARRAY \@b ARRAY \@b
396+
HASH \%a HASH \%b HASH { %a, %b }
397+
398+
=head1 INTERPOLATION
399+
400+
=head1 DIRECTIVES
318401
319402
=head1 AUTHOR
320403
@@ -329,4 +412,3 @@ This module is free software; you can redistribute it and/or modify it under
329412
the same terms as Perl itself.
330413
331414
=cut
332-

t/00-base.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use Test::More tests => 3;
77
my $T_CLASS;
88

99
BEGIN {
10-
$T_CLASS = 'Config::Loader';
10+
$T_CLASS = 'Config::Processor';
1111
use_ok($T_CLASS);
1212
}
1313

1414
can_ok( $T_CLASS, 'new' );
15-
my $config_loader = new_ok($T_CLASS);
15+
my $config_processor = new_ok($T_CLASS);

t/01-accessors.t

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@ use strict;
33
use warnings;
44

55
use Test::More tests => 8;
6-
use Config::Loader;
6+
use Config::Processor;
77

8-
my $CONFIG_LOADER = Config::Loader->new();
8+
my $CONFIG_PROCESSOR = Config::Processor->new();
99

10-
can_ok( $CONFIG_LOADER, 'interpolate_variables' );
11-
can_ok( $CONFIG_LOADER, 'process_directives' );
10+
can_ok( $CONFIG_PROCESSOR, 'interpolate_variables' );
11+
can_ok( $CONFIG_PROCESSOR, 'process_directives' );
1212

13-
t_interpolate_variables($CONFIG_LOADER);
14-
t_process_directives($CONFIG_LOADER);
13+
t_interpolate_variables($CONFIG_PROCESSOR);
14+
t_process_directives($CONFIG_PROCESSOR);
1515

1616

1717
sub t_interpolate_variables {
18-
my $config_loader = shift;
18+
my $config_processor = shift;
1919

20-
my $interpolate_variables = $config_loader->interpolate_variables;
20+
my $interpolate_variables = $config_processor->interpolate_variables;
2121
is( $interpolate_variables, 1, 'get variable interpolation switch value' );
2222

23-
$config_loader->interpolate_variables(undef);
24-
is( $config_loader->interpolate_variables,
23+
$config_processor->interpolate_variables(undef);
24+
is( $config_processor->interpolate_variables,
2525
undef, 'disable variable interpolation' );
2626

27-
$config_loader->interpolate_variables(1);
28-
is( $config_loader->interpolate_variables, 1,
27+
$config_processor->interpolate_variables(1);
28+
is( $config_processor->interpolate_variables, 1,
2929
"enable variable interpolation" );
3030

3131
return;
3232
}
3333

3434
sub t_process_directives {
35-
my $config_loader = shift;
35+
my $config_processor = shift;
3636

37-
my $process_directives = $config_loader->process_directives;
37+
my $process_directives = $config_processor->process_directives;
3838
is( $process_directives, 1, 'get directive processing switch value' );
3939

40-
$config_loader->process_directives(undef);
41-
is( $config_loader->process_directives,
40+
$config_processor->process_directives(undef);
41+
is( $config_processor->process_directives,
4242
undef, 'disable directive processing' );
4343

44-
$config_loader->process_directives(1);
45-
is( $config_loader->process_directives, 1, "enable directive processing" );
44+
$config_processor->process_directives(1);
45+
is( $config_processor->process_directives, 1, "enable directive processing" );
4646

4747
return;
4848
}

0 commit comments

Comments
 (0)