- applied patches by Jason Rhinelander <jagerman@jagerman.com>:
	  	o bugfix: multiple levels if include files didn't
		  work properly.

		o new option -IncludeDirectories, which allows
		  to include all files of a directory. The directory
		  must be specified by -ConfigFile as usual.

		o new option -IncludeGlob, which allows to
		  use globs (wildcards) to include multiple files.

		o -ConfigPath can be speciefied using a single
		  scalar value instead of an array if there is only
		  one path.

		o bugfix: quotes from quoted block names were
		  not removed properly.

		o fixes and updates for tests (make test) for
		  the above patches.
	   
	   Thanks a lot Jason.

	 - fixed number of tests in run.t

	 - applied suggestion by Eric Kisiel <eric.kisiel@adelphia.com>:
	   ::Extended::keys() returns an empty hash if the
	   referring object is not hash.

	 - fixed bug #14770, "Use of uninitialized value.." during
	   environment variable interpolation.


git-svn-id: http://dev.catalyst.perl.org/repos/Config-General/trunk@57 be1acefe-a474-0410-9a34-9b3221f2030f
This commit is contained in:
Thomas von Dein
2009-10-10 16:36:29 +00:00
parent 57244f6eea
commit 80bcb7ddae
10 changed files with 251 additions and 58 deletions

112
t/run.t
View File

@@ -6,7 +6,7 @@
#
# Under normal circumstances every test should succeed.
BEGIN { $| = 1; print "1..22\n";}
BEGIN { $| = 1; print "1..24\n";}
use lib "blib/lib";
use Config::General;
use Data::Dumper;
@@ -257,10 +257,12 @@ my $conf22 = Config::General->new(
my %h22 = $conf22->getall;
my %expected_h22 = (
'sub3_seen' => 'yup',
'sub2_seen' => 'yup',
'sub1_seen' => 'yup',
'fruit' => 'mango',
'sub3_seen' => 'yup',
'sub2_seen' => 'yup',
'sub2b_seen' => 'yup',
'sub1_seen' => 'yup',
'sub1b_seen' => 'yup',
'fruit' => 'mango',
);
if (&comp(\%h22, \%expected_h22)) {
@@ -273,6 +275,100 @@ else {
}
pause;
# Testing IncludeDirectories option
my $conf23 = Config::General->new(
-String => "<<include t/sub1>>",
-IncludeDirectories => 1
);
my %h23 = $conf23->getall;
my %expected_h23 = (
fruit => 'mango',
sub1_seen => 'yup',
sub1b_seen => 'yup',
test => 'value',
test2 => 'value2',
test3 => 'value3'
);
if (&comp(\%h23, \%expected_h23)) {
print "ok\n";
print STDERR " .. ok # including a directory with -IncludeDirectories\n";
}
else {
print "23 not ok\n";
print STDERR "23 not ok\n";
}
pause;
# Testing IncludeGlob option
my $conf24 = Config::General->new(
-String => "<<include t/sub1/cfg.sub[123]{c,d,e}>>",
-IncludeGlob => 1
);
my %h24 = $conf24->getall;
my %expected_h24 = (
test => 'value',
test2 => 'value2',
test3 => 'value3'
);
if (&comp(\%h24, \%expected_h24)) {
print "ok\n";
print STDERR " .. ok # including multiple files via glob pattern with -IncludeGlob\n";
}
else {
print "24 not ok\n";
print STDERR "24 not ok\n";
}
pause;
# Testing block and block name quoting
my $conf25 = Config::General->new(
-String => <<TEST,
<block "/">
opt1 val1
</block>
<"block2 /">
opt2 val2
</"block2 /">
<"block 3" "/">
opt3 val3
</"block 3">
<block4 />
opt4 val4
</block4>
TEST
-SlashIsDirectory => 1
);
my %h25 = $conf25->getall;
my %expected_h25 = (
block => { '/' => { opt1 => 'val1' } },
'block2 /' => { opt2 => 'val2' },
'block 3' => { '/' => { opt3 => 'val3' } },
block4 => { '/' => { opt4 => 'val4' } }
);
if (&comp(\%h25, \%expected_h25)) {
print "ok\n";
print STDERR " .. ok # block and block name quoting\n";
}
else {
print "25 not ok\n";
print STDERR "25 not ok\n";
}
pause;
@@ -293,9 +389,11 @@ sub p {
sub comp {
my($a, $b) = @_;
foreach my $key (keys %{$a}) {
my %keys = map { $_ => 1 } keys %$a, keys %$b;
foreach my $key (keys %keys) {
return 0 unless exists $a->{$key} and exists $b->{$key};
if(ref($a->{$key}) eq "HASH") {
&comp($a->{$key},$b->{$key});
return 0 unless &comp($a->{$key},$b->{$key});
next;
}
elsif(ref($a->{$key}) eq "ARRAY") {

View File

@@ -1,3 +1,3 @@
fruit = mango
sub3_seen = yup
sub1_seen = yup

View File

@@ -1,4 +1,5 @@
fruit = pear
sub2_seen = yup
<<include ../cfg.sub1>>
<<include ../cfg.sub1>>
<<include ../cfg.sub1b>>

View File

@@ -2,4 +2,4 @@ fruit = apple
sub3_seen = yup
<<include ../cfg.sub2>>
<<include ../cfg.sub2b>>