Revision history for Config-Any
+0.11 Mon 28 Jan 2008
+ - fix subsection parsing for existing keys in INI files (RT #32726)
+ - use from_json() if JSON version 2.x is available
+ - refactor the test suite slightly
+
0.10 Tue 11 Dec 2007
- promote dev release to stable
require Config::Tiny;
my $config = Config::Tiny->read( $file );
-
- my $main = delete $config->{ _ };
- my $out;
- $out->{ $_ } = $main->{ $_ } for keys %$main;
+ my $out = delete $config->{ _ } || {};
for my $k ( keys %$config ) {
- my @keys = split /\s+/, $k if $MAP_SECTION_SPACE_TO_NESTED_KEY;
+ my @keys = split /\s+/, $k;
my $ref = $config->{ $k };
- if ( @keys > 1 ) {
+ if ( $MAP_SECTION_SPACE_TO_NESTED_KEY && @keys > 1 ) {
my ( $a, $b ) = @keys[ 0, 1 ];
$out->{ $a }->{ $b } = $ref;
}
else {
- $out->{ $k } = $ref;
+ $out->{ $k } = { %{ $out->{ $k } || {} }, %$ref };
}
}
+
return $out;
}
eval { require JSON::Syck; };
if ( $@ ) {
require JSON;
- return JSON::jsonToObj( $content );
+ eval { JSON->VERSION( 2 ); };
+ return $@ ? JSON::jsonToObj( $content ) : JSON::from_json( $content );
}
else {
return JSON::Syck::Load( $content );
+use strict;
+use warnings;
+
use Test::More tests => 6;
BEGIN {
+use strict;
+use warnings;
+
use Test::More tests => 10;
use_ok( 'Config::Any' );
-use Test::More tests => 4;
+use strict;
+use warnings;
+use Test::More;
use Config::Any::General;
-my $config = eval { Config::Any::General->load( 't/conf/conf.conf' ) };
+if ( !Config::Any::General->is_supported ) {
+ plan skip_all => 'Config::General format not supported';
+}
+else {
+ plan tests => 4;
+}
-SKIP: {
- skip "Couldn't Load Config::General plugin", 4 if $@;
+{
+ my $config = Config::Any::General->load( 't/conf/conf.conf' );
ok( $config );
is( $config->{ name }, 'TestApp' );
ok( exists $config->{ Component } );
+}
- $config = eval {
- Config::Any::General->load( 't/conf/conf.conf',
- { -LowerCaseNames => 1 } );
- };
-
+{
+ my $config = Config::Any::General->load( 't/conf/conf.conf',
+ { -LowerCaseNames => 1 } );
ok( exists $config->{ component } );
}
-use Test::More tests => 9;
+use strict;
+use warnings;
+use Test::More;
use Config::Any::INI;
-my $config = eval { Config::Any::INI->load( 't/conf/conf.ini' ) };
-my $simpleconfig = eval { Config::Any::INI->load( 't/conf/conf2.ini' ) };
+if ( !Config::Any::INI->is_supported ) {
+ plan skip_all => 'INI format not supported';
+}
+else {
+ plan tests => 11;
+}
-SKIP: {
- skip "Couldn't Load INI plugin", 6 if $@;
- ok( $config, "loaded INI config #1" );
+{
+ my $config = Config::Any::INI->load( 't/conf/conf.ini' );
+ ok( $config, 'config loaded' );
is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
- is( $config->{ Component }->{ Controller::Foo }->{ foo },
+ is( $config->{ Component }->{ 'Controller::Foo' }->{ foo },
'bar', "nested hashref hack lookup succeeded" );
+}
- ok( $simpleconfig, "loaded INI config #1" );
- is( $simpleconfig->{ name }, 'TestApp', "toplevel key lookup succeeded" );
- is( $simpleconfig->{ Controller::Foo }->{ foo },
+{
+ my $config = Config::Any::INI->load( 't/conf/conf2.ini' );
+ ok( $config, 'config loaded' );
+ is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
+ is( $config->{ 'Controller::Foo' }->{ foo },
'bar', "nested hashref hack lookup succeeded" );
}
-$Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
-my $unspaced_config = eval { Config::Any::INI->load( 't/conf/conf.ini' ); };
-SKIP: {
- skip "Couldn't load INI plugin", 3 if $@;
- ok( $unspaced_config, "loaded INI config #1 in no-map-space mode" );
- is( $unspaced_config->{ name },
- 'TestApp', "toplevel key lookup succeeded" );
- is( $unspaced_config->{ 'Component Controller::Foo' }->{ foo },
+{
+ local $Config::Any::INI::MAP_SECTION_SPACE_TO_NESTED_KEY = 0;
+ my $config = Config::Any::INI->load( 't/conf/conf.ini' );
+ ok( $config, 'config loaded (no-map-space mode)' );
+ is( $config->{ name }, 'TestApp', "toplevel key lookup succeeded" );
+ is( $config->{ 'Component Controller::Foo' }->{ foo },
'bar', "unnested key lookup succeeded" );
}
+
+{
+ my $config = Config::Any::INI->load( 't/conf/subsections.ini' );
+
+ my %expected
+ = ( section1 =>
+ { a => 1, subsection1 => { b => 2 }, subsection2 => { c => 3 } }
+ );
+ ok( $config, 'config loaded' );
+ is_deeply( $config, \%expected, 'subsections parsed properly' );
+}
-use Test::More tests => 2;
+use strict;
+use warnings;
+use Test::More;
use Config::Any::JSON;
-my $config = eval { Config::Any::JSON->load( 't/conf/conf.json' ) };
+if ( !Config::Any::JSON->is_supported ) {
+ plan skip_all => 'JSON format not supported';
+}
+else {
+ plan tests => 2;
+}
-SKIP: {
- skip "Couldn't Load JSON plugin", 2 if $@;
+{
+ my $config = Config::Any::JSON->load( 't/conf/conf.json' );
ok( $config );
is( $config->{ name }, 'TestApp' );
}
+use strict;
+use warnings;
+
use Test::More tests => 3;
use Config::Any::Perl;
-my $file = 't/conf/conf.pl';
-my $config = eval { Config::Any::Perl->load( $file ) };
-
-SKIP: {
- skip "Couldn't Load Perl plugin", 3 if $@;
+{
+ my $file = 't/conf/conf.pl';
+ my $config = Config::Any::Perl->load( $file );
ok( $config );
is( $config->{ name }, 'TestApp' );
- my $config_2 = eval { Config::Any::Perl->load( $file ) };
-
- is_deeply( $config_2, $config, 'multiple loads of perl configs' );
+ my $config_load2 = Config::Any::Perl->load( $file );
+ is_deeply( $config_load2, $config, 'multiple loads of the same file' );
}
+
-use Test::More tests => 2;
+use strict;
+use warnings;
+use Test::More;
use Config::Any::XML;
-my $config = eval { Config::Any::XML->load( 't/conf/conf.xml' ) };
+if ( !Config::Any::XML->is_supported ) {
+ plan skip_all => 'XML format not supported';
+}
+else {
+ plan tests => 2;
+}
-SKIP: {
- skip "Couldn't Load XML plugin", 2 if $@;
+{
+ my $config = Config::Any::XML->load( 't/conf/conf.xml' );
ok( $config );
is( $config->{ name }, 'TestApp' );
}
-use Test::More tests => 2;
+use strict;
+use warnings;
+use Test::More;
use Config::Any::YAML;
-my $config = eval { Config::Any::YAML->load( 't/conf/conf.yml' ) };
+if ( !Config::Any::YAML->is_supported ) {
+ plan skip_all => 'YAML format not supported';
+}
+else {
+ plan tests => 2;
+}
-SKIP: {
- skip "Couldn't Load YAML plugin", 2 if $@;
+{
+ my $config = Config::Any::YAML->load( 't/conf/conf.yml' );
ok( $config );
is( $config->{ name }, 'TestApp' );
}
-use Test::More tests => 3;
-
use strict;
use warnings;
+use Test::More tests => 3;
+
use Config::Any;
use Config::Any::YAML;
-#!perl -T
-
+use strict;
+use warnings;
use Test::More;
+
eval "use Test::Pod::Coverage 1.04";
+
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage"
if $@;
all_pod_coverage_ok();
-#!perl -T
-
+use strict;
+use warnings;
use Test::More;
+
eval "use Test::Pod 1.14";
+
plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
all_pod_files_ok();