From: Brian Cassidy Date: Tue, 18 Apr 2006 23:42:16 +0000 (+0000) Subject: updated to latest ConfigLoader X-Git-Tag: 5.7099_04~632 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=aceb04435e7349e614c4bef4011de403d7e8df0c updated to latest ConfigLoader --- diff --git a/lib/Catalyst/Plugin/ConfigLoader.pm b/lib/Catalyst/Plugin/ConfigLoader.pm index 0fcbc70..f073ccf 100644 --- a/lib/Catalyst/Plugin/ConfigLoader.pm +++ b/lib/Catalyst/Plugin/ConfigLoader.pm @@ -10,7 +10,7 @@ use Module::Pluggable::Fast require => 1; use Data::Visitor::Callback; -our $VERSION = '0.04'; +our $VERSION = '0.05'; =head1 NAME @@ -30,17 +30,21 @@ Catalyst::Plugin::ConfigLoader - Load config files of various types =head1 DESCRIPTION -This mdoule will attempt to load find and load a configuration +This module will attempt to load find and load a configuration file of various types. Currently it supports YAML, JSON, XML, INI and Perl formats. +To support the distinction between development and production environments, +this module will also attemp to load a local config (e.g. myapp_local.yaml) +which will override any duplicate settings. + =head1 METHODS =head2 setup( ) This method is automatically called by Catalyst's setup routine. It will attempt to use each plugin and, once a file has been successfully -loaded, set the C section. +loaded, set the C section. =cut @@ -58,7 +62,7 @@ sub setup { push @files, $path; } else { - push @files, "$path.$_" for @extensions; + @files = map { ( "$path.$_", "${path}_local.$_" ) } @extensions; } for( @files ) { @@ -84,15 +88,21 @@ at runtime. If you need to do this to properly configure any plugins, it's important to load ConfigLoader before them. ConfigLoader provides a default finalize_config method which walks through the loaded config hash and replaces any strings -beginning with C<< __HOME__/ >> with the full path to -the file inside the app's home directory. +beginning containing C<__HOME__> with the full path to +app's home directory (i.e. C<$c-Epath_to('')> ). +You can also use C<__path_to('foo/bar')__> which translates to +C<$c-Epath_to('foo', 'bar')> =cut sub finalize_config { my $c = shift; my $v = Data::Visitor::Callback->new( - plain_value => sub { s[^__HOME__/(.+)$][ $c->path_to($1) ]e } + plain_value => sub { + return unless defined $_; + s[__HOME__][ $c->path_to( '' ) ]e; + s[__path_to\((.+)\)__][ $c->path_to( split( '/', $1 ) ) ]e; + } ); $v->visit( $c->config ); } @@ -133,4 +143,4 @@ it under the same terms as Perl itself. =cut -1; \ No newline at end of file +1;