lots of Config::Any fixes, brought in C::Any testsuite (refactored, partly, from...
[p5sagit/Config-Any.git] / lib / Config / Any / XML.pm
index a37a2f2..42a8380 100644 (file)
@@ -45,9 +45,29 @@ sub load {
 \r
     require XML::Simple;\r
     XML::Simple->import;\r
-    my $config = XMLin( $file, ForceArray => [ qw( component model view controller ) ] );\r
+    my $config = XMLin( \r
+               $file, \r
+               ForceArray => [ qw( component model view controller ) ],\r
+       );\r
 \r
-    return $config;\r
+       return $class->_coerce($config);\r
+}\r
+\r
+sub _coerce {\r
+       # coerce the XML-parsed config into the correct format\r
+       my $class = shift;\r
+       my $config = shift;\r
+       my $out;\r
+       for my $k (keys %$config) {\r
+               my $ref = $config->{$k};\r
+               my $name = ref $ref ? delete $ref->{name} : undef;\r
+               if (defined $name) {\r
+                       $out->{$k}->{$name} = $ref;     \r
+               } else {\r
+                       $out->{$k} = $ref;\r
+               }\r
+       }\r
+       $out;\r
 }\r
 \r
 =head1 AUTHOR\r
@@ -56,6 +76,8 @@ sub load {
 \r
 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>\r
 \r
+=item * Joel Bernstein E<lt>rataxis@cpan.orgE<gt>\r
+\r
 =back\r
 \r
 =head1 COPYRIGHT AND LICENSE\r
@@ -79,4 +101,4 @@ it under the same terms as Perl itself.
 \r
 =cut\r
 \r
-1;
\ No newline at end of file
+1;\r