Commit | Line | Data |
b2d85594 |
1 | package Catalyst::Plugin::ConfigLoader::XML;\r |
2 | \r |
3 | use strict;\r |
4 | use warnings;\r |
5 | \r |
6 | =head1 NAME\r |
7 | \r |
8 | Catalyst::Plugin::ConfigLoader::XML - Load XML config files\r |
9 | \r |
10 | =head1 DESCRIPTION\r |
11 | \r |
12 | Loads 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 |
25 | Attempts to load C<$file> as an XML file.\r |
26 | \r |
27 | =cut\r |
28 | \r |
29 | sub 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 |
66 | Copyright 2006 by Brian Cassidy\r |
67 | \r |
68 | This library is free software; you can redistribute it and/or modify\r |
69 | it 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 |
81 | 1; |