initial import
[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
12our $VERSION = '0.01';\r
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
20 package MyApp;\r
21 \r
22 use Catalyst( ConfigLoader );\r
23 \r
24 # by default myapp.* will be loaded\r
25 # you can specify a file if you'd like\r
26 __PACKAGE__->config( file = > 'config.yaml' );\r
27 \r
28\r
29=head1 DESCRIPTION\r
30\r
31This mdoule will attempt to load find and load a configuration\r
32file of various types. Currently it supports YAML, JSON, XML,\r
33INI and Perl formats.\r
34\r
35=head1 METHODS\r
36\r
37=head2 setup( )\r
38\r
39This method is automatically called by Catalyst's setup routine. It will\r
40attempt to use each plugin and set the C<config()> section once a file has been\r
41successfully loaded.\r
42\r
43=cut\r
44\r
45sub setup {\r
46 my $c = shift;\r
47 my $confpath = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );\r
48 \r
49 for my $loader ( $c->_config_loaders ) {\r
50 my $config = $loader->load( $confpath );\r
51 if( $config ) {\r
52 $c->config( $config );\r
53 last;\r
54 }\r
55 }\r
56\r
57 $c->NEXT::setup( @_ );\r
58}\r
59\r
60=head1 AUTHOR\r
61\r
62=over 4 \r
63\r
64=item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>\r
65\r
66=back\r
67\r
68=head1 COPYRIGHT AND LICENSE\r
69\r
70Copyright 2006 by Brian Cassidy\r
71\r
72This library is free software; you can redistribute it and/or modify\r
73it under the same terms as Perl itself. \r
74\r
75=head1 SEE ALSO\r
76\r
77=over 4 \r
78\r
79=item * L<Catalyst>\r
80\r
81=back\r
82\r
83=cut\r
84\r
851;