pod cleanups
[p5sagit/Config-Any.git] / lib / Config / Any / XML.pm
CommitLineData
f0e3c221 1package Config::Any::XML;
2
3use strict;
4use warnings;
5
dcfb1d1d 6use base 'Config::Any::Base';
7
f0e3c221 8=head1 NAME
9
10Config::Any::XML - Load XML config files
11
12=head1 DESCRIPTION
13
14Loads XML files. Example:
15
16 <config>
17 <name>TestApp</name>
18 <component name="Controller::Foo">
19 <foo>bar</foo>
20 </component>
21 <model name="Baz">
22 <qux>xyzzy</qux>
23 </model>
24 </config>
25
26=head1 METHODS
27
28=head2 extensions( )
29
30return an array of valid extensions (C<xml>).
31
32=cut
33
34sub extensions {
35 return qw( xml );
36}
37
38=head2 load( $file )
39
40Attempts to load C<$file> as an XML file.
41
42=cut
43
44sub load {
45 my $class = shift;
46 my $file = shift;
7d9d2803 47 my $args = shift || {};
f0e3c221 48
49 require XML::Simple;
92a04e78 50 my $config = XML::Simple::XMLin(
51 $file,
f0e3c221 52 ForceArray => [ qw( component model view controller ) ],
7d9d2803 53 %$args
f0e3c221 54 );
55
92a04e78 56 return $class->_coerce( $config );
f0e3c221 57}
58
59sub _coerce {
60 # coerce the XML-parsed config into the correct format
92a04e78 61 my $class = shift;
f0e3c221 62 my $config = shift;
63 my $out;
92a04e78 64 for my $k ( keys %$config ) {
65 my $ref = $config->{ $k };
bb941906 66 my $name = ref $ref eq 'HASH' ? delete $ref->{ name } : undef;
92a04e78 67 if ( defined $name ) {
68 $out->{ $k }->{ $name } = $ref;
69 }
70 else {
71 $out->{ $k } = $ref;
f0e3c221 72 }
73 }
74 $out;
75}
76
dcfb1d1d 77=head2 requires_all_of( )
72628dc7 78
e7be073a 79Specifies that this module requires L<XML::Simple> and L<XML::NamespaceSupport>
80in order to work.
72628dc7 81
82=cut
83
e7be073a 84sub requires_all_of { 'XML::Simple', 'XML::NamespaceSupport' }
72628dc7 85
11501cf7 86=head1 CAVEATS
87
88=head2 Strict Mode
89
90If, by some chance, L<XML::Simple> has already been loaded with the strict
91flag turned on, then you will likely get errors as warnings will become
92fatal exceptions and certain arguments to XMLin() will no longer be optional.
93
94See L<XML::Simple's strict mode documentation|XML::Simple/STRICT_MODE> for
95more information.
96
a918b0b8 97=head1 AUTHORS
f0e3c221 98
20190ef7 99Brian Cassidy <bricas@cpan.org>
f0e3c221 100
20190ef7 101Joel Bernstein <rataxis@cpan.org>
f0e3c221 102
103=head1 COPYRIGHT AND LICENSE
104
3d43e104 105Copyright 2006-2016 by Brian Cassidy
f0e3c221 106
107This library is free software; you can redistribute it and/or modify
19f6cb63 108it under the same terms as Perl itself.
f0e3c221 109
110=head1 SEE ALSO
111
19f6cb63 112=over 4
f0e3c221 113
114=item * L<Catalyst>
115
116=item * L<Config::Any>
117
118=item * L<XML::Simple>
119
120=back
121
122=cut
123
1241;