1 package Catalyst::Plugin::ConfigLoader;
\r
7 use Module::Pluggable::Fast
\r
8 name => '_config_loaders',
\r
9 search => [ __PACKAGE__ ],
\r
12 our $VERSION = '0.03';
\r
16 Catalyst::Plugin::ConfigLoader - Load config files of various types
\r
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
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
33 This mdoule will attempt to load find and load a configuration
\r
34 file of various types. Currently it supports YAML, JSON, XML,
\r
35 INI and Perl formats.
\r
41 This method is automatically called by Catalyst's setup routine. It will
\r
42 attempt to use each plugin and, once a file has been successfully
\r
43 loaded, set the C<config()> section.
\r
49 my $path = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );
\r
51 my( $extension ) = ( $path =~ /\.(.{1,4})$/ );
\r
53 for my $loader ( $c->_config_loaders ) {
\r
55 my @extensions = $loader->extensions;
\r
57 next unless grep { $_ eq $extension } @extensions;
\r
61 push @files, "$path.$_" for @extensions;
\r
66 my $config = $loader->load( $_ );
\r
68 $c->config( $config );
\r
74 $c->NEXT::setup( @_ );
\r
81 =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
\r
85 =head1 COPYRIGHT AND LICENSE
\r
87 Copyright 2006 by Brian Cassidy
\r
89 This library is free software; you can redistribute it and/or modify
\r
90 it under the same terms as Perl itself.
\r