initial import
[catagits/Catalyst-Plugin-ConfigLoader.git] / lib / Catalyst / Plugin / ConfigLoader / XML.pm
CommitLineData
b2d85594 1package Catalyst::Plugin::ConfigLoader::XML;\r
2\r
3use strict;\r
4use warnings;\r
5\r
6=head1 NAME\r
7\r
8Catalyst::Plugin::ConfigLoader::XML - Load XML config files\r
9\r
10=head1 DESCRIPTION\r
11\r
12Loads XML files. Example:\r
13\r
14 <config>\r
15 <name>TestApp</name>\r
16 <component name="Controller::Config">\r
17 <foo>bar</foo>\r
18 </component>\r
19 </config>\r
20\r
21=head1 METHODS\r
22\r
23=head2 load( $file )\r
24\r
25Attempts to load C<$file> as an XML file.\r
26\r
27=cut\r
28\r
29sub load {\r
30 my $class = shift;\r
31 my $confpath = shift;\r
32\r
33 my $file;\r
34 if( $confpath =~ /\.(.{3})$/ ) {\r
35 return unless $1 eq 'xml';\r
36 $file = $confpath;\r
37 }\r
38 else {\r
39 $file = "$confpath.xml";\r
40 }\r
41 \r
42 return unless -f $file;\r
43\r
44 require XML::Simple;\r
45 XML::Simple->import;\r
46 my $config = XMLin( $file, ForceArray => [ 'component' ] );\r
47\r
48 my $components = delete $config->{ component };\r
49 foreach my $element ( keys %$components ) {\r
50 $config->{ $element } = $components->{ $element };\r
51 }\r
52\r
53 return $config;\r
54}\r
55\r
56=head1 AUTHOR\r
57\r
58=over 4 \r
59\r
60=item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>\r
61\r
62=back\r
63\r
64=head1 COPYRIGHT AND LICENSE\r
65\r
66Copyright 2006 by Brian Cassidy\r
67\r
68This library is free software; you can redistribute it and/or modify\r
69it under the same terms as Perl itself. \r
70\r
71=head1 SEE ALSO\r
72\r
73=over 4 \r
74\r
75=item * L<Catalyst>\r
76\r
77=back\r
78\r
79=cut\r
80\r
811;