pod fixes
[catagits/Catalyst-Plugin-ConfigLoader.git] / lib / Catalyst / Plugin / ConfigLoader.pm
CommitLineData
b2d85594 1package Catalyst::Plugin::ConfigLoader;\r
2\r
3use strict;\r
4use warnings;\r
5\r
6use NEXT;\r
7use Module::Pluggable::Fast\r
8 name => '_config_loaders',\r
9 search => [ __PACKAGE__ ],\r
10 require => 1;\r
11\r
d2afa071 12our $VERSION = '0.03';\r
b2d85594 13\r
14=head1 NAME\r
15\r
16Catalyst::Plugin::ConfigLoader - Load config files of various types\r
17\r
18=head1 SYNOPSIS\r
19\r
c7413665 20 package MyApp;\r
21 \r
d2afa071 22 # ConfigLoader should be first in your list so\r
23 # other plugins can get the config information\r
24 use Catalyst qw( ConfigLoader ... );\r
b2d85594 25 \r
26 # by default myapp.* will be loaded\r
27 # you can specify a file if you'd like\r
28 __PACKAGE__->config( file = > 'config.yaml' );\r
29 \r
30\r
31=head1 DESCRIPTION\r
32\r
33This mdoule will attempt to load find and load a configuration\r
34file of various types. Currently it supports YAML, JSON, XML,\r
35INI and Perl formats.\r
36\r
37=head1 METHODS\r
38\r
39=head2 setup( )\r
40\r
41This method is automatically called by Catalyst's setup routine. It will\r
d6277728 42attempt to use each plugin and, once a file has been successfully\r
43loaded, set the C<config()> section.\r
b2d85594 44\r
45=cut\r
46\r
47sub setup {\r
c7413665 48 my $c = shift;\r
49 my $path = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );\r
50\r
51 my( $extension ) = ( $path =~ /\.(.{1,4})$/ );\r
b2d85594 52 \r
53 for my $loader ( $c->_config_loaders ) {\r
c7413665 54 my @files;\r
55 my @extensions = $loader->extensions;\r
56 if( $extension ) {\r
57 next unless grep { $_ eq $extension } @extensions;\r
58 push @files, $path;\r
59 }\r
60 else {\r
61 push @files, "$path.$_" for @extensions;\r
62 }\r
63\r
64 for( @files ) {\r
65 next unless -f $_;\r
66 my $config = $loader->load( $_ );\r
67 if( $config ) {\r
68 $c->config( $config );\r
69 last;\r
70 }\r
b2d85594 71 }\r
72 }\r
73\r
74 $c->NEXT::setup( @_ );\r
75}\r
76\r
77=head1 AUTHOR\r
78\r
79=over 4 \r
80\r
81=item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>\r
82\r
83=back\r
84\r
85=head1 COPYRIGHT AND LICENSE\r
86\r
87Copyright 2006 by Brian Cassidy\r
88\r
89This library is free software; you can redistribute it and/or modify\r
90it under the same terms as Perl itself. \r
91\r
92=head1 SEE ALSO\r
93\r
94=over 4 \r
95\r
96=item * L<Catalyst>\r
97\r
98=back\r
99\r
100=cut\r
101\r
1021;