| Config-Any documentation | Contained in the Config-Any distribution. |
Config::Any::XML - Load XML config files
Loads XML files. Example:
<config>
<name>TestApp</name>
<component name="Controller::Foo">
<foo>bar</foo>
</component>
<model name="Baz">
<qux>xyzzy</qux>
</model>
</config>
return an array of valid extensions (xml).
Attempts to load $file as an XML file.
Specifies that this module requires XML::Simple in order to work.
If, by some chance, XML::Simple has already been loaded with the strict flag turned on, then you will likely get errors as warnings will become fatal exceptions and certain arguments to XMLin() will no longer be optional.
See XML::Simple's strict mode documentation for more information.
Brian Cassidy <bricas@cpan.org>
Joel Bernstein <rataxis@cpan.org>
Copyright 2006-2011 by Brian Cassidy
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Config-Any documentation | Contained in the Config-Any distribution. |
package Config::Any::XML; use strict; use warnings; use base 'Config::Any::Base';
sub extensions { return qw( xml ); }
sub load { my $class = shift; my $file = shift; my $args = shift || {}; require XML::Simple; my $config = XML::Simple::XMLin( $file, ForceArray => [ qw( component model view controller ) ], %$args ); 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 eq 'HASH' ? delete $ref->{ name } : undef; if ( defined $name ) { $out->{ $k }->{ $name } = $ref; } else { $out->{ $k } = $ref; } } $out; }
sub requires_all_of { 'XML::Simple' }
1;