From: Brian Cassidy Date: Mon, 16 Nov 2009 12:49:59 +0000 (+0000) Subject: ensure XML loader's _coerce() method checks specifically for HASH refs X-Git-Tag: v0.18~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=commitdiff_plain;h=bb941906c239836c60ecce6d451cd896898f1efd ensure XML loader's _coerce() method checks specifically for HASH refs --- diff --git a/Changes b/Changes index 49e7fc8..b507bd7 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for Config-Any 0.18 XXX + - ensure XML loader's _coerce() method checks specifically for HASH refs - add YAML::XS to the top of the YAML loaders list 0.17 Thu 05 Feb 2009 diff --git a/lib/Config/Any/XML.pm b/lib/Config/Any/XML.pm index 46060c4..eca183f 100644 --- a/lib/Config/Any/XML.pm +++ b/lib/Config/Any/XML.pm @@ -57,14 +57,13 @@ sub load { } sub _coerce { - # coerce the XML-parsed config into the correct format my $class = shift; my $config = shift; my $out; for my $k ( keys %$config ) { my $ref = $config->{ $k }; - my $name = ref $ref ? delete $ref->{ name } : undef; + my $name = ref $ref eq 'HASH' ? delete $ref->{ name } : undef; if ( defined $name ) { $out->{ $k }->{ $name } = $ref; } diff --git a/t/54-xml.t b/t/54-xml.t index e2badee..45fd66e 100644 --- a/t/54-xml.t +++ b/t/54-xml.t @@ -8,7 +8,7 @@ if ( !Config::Any::XML->is_supported ) { plan skip_all => 'XML format not supported'; } else { - plan tests => 4; + plan tests => 6; } { @@ -30,3 +30,12 @@ SKIP: { ok( !$config, 'config load failed' ); ok( $@, "error thrown ($@)" ); } + +# test conf file with array ref +{ + my $file = 't/conf/conf_arrayref.xml'; + my $config = eval { Config::Any::XML->load( $file ) }; + + ok( $config, 'config loaded' ); + ok( !$@, 'no error thrown' ); +} diff --git a/t/conf/conf_arrayref.xml b/t/conf/conf_arrayref.xml new file mode 100644 index 0000000..984cd57 --- /dev/null +++ b/t/conf/conf_arrayref.xml @@ -0,0 +1,10 @@ + +
+ + + + + + + submit +