X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FConfig-Any.git;a=blobdiff_plain;f=lib%2FConfig%2FAny%2FXML.pm;h=42a83806f9d6d60f221cf98801452d7b24b2267b;hp=a37a2f2513df84352887ae8c947e2b45cfaba9f1;hb=e967a60fa6fb5adeb6ead013b0b60289b2a92e2e;hpb=59a8045203653a6f6cbccc3c24eb3884fba40ddc diff --git a/lib/Config/Any/XML.pm b/lib/Config/Any/XML.pm index a37a2f2..42a8380 100644 --- a/lib/Config/Any/XML.pm +++ b/lib/Config/Any/XML.pm @@ -45,9 +45,29 @@ sub load { require XML::Simple; XML::Simple->import; - my $config = XMLin( $file, ForceArray => [ qw( component model view controller ) ] ); + my $config = XMLin( + $file, + ForceArray => [ qw( component model view controller ) ], + ); - return $config; + return $class->_coerce($config); +} + +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; + if (defined $name) { + $out->{$k}->{$name} = $ref; + } else { + $out->{$k} = $ref; + } + } + $out; } =head1 AUTHOR @@ -56,6 +76,8 @@ sub load { =item * Brian Cassidy Ebricas@cpan.orgE +=item * Joel Bernstein Erataxis@cpan.orgE + =back =head1 COPYRIGHT AND LICENSE @@ -79,4 +101,4 @@ it under the same terms as Perl itself. =cut -1; \ No newline at end of file +1;