X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FConfigLoader.pm;h=0fcbc704af057709680571fb8ef8389b8d45b9a2;hp=0ba9f9915d83c4fb80cf06c6133a1e8f6964eddd;hb=2fb22e6e6967ab08a4ea3ca996378e59fe2de2c6;hpb=d0d4d785ca0a5c8e0bc62daddd6f5ab6c0b60eca diff --git a/lib/Catalyst/Plugin/ConfigLoader.pm b/lib/Catalyst/Plugin/ConfigLoader.pm index 0ba9f99..0fcbc70 100644 --- a/lib/Catalyst/Plugin/ConfigLoader.pm +++ b/lib/Catalyst/Plugin/ConfigLoader.pm @@ -8,8 +8,9 @@ use Module::Pluggable::Fast name => '_config_loaders', search => [ __PACKAGE__ ], require => 1; +use Data::Visitor::Callback; -our $VERSION = '0.03'; +our $VERSION = '0.04'; =head1 NAME @@ -25,8 +26,7 @@ Catalyst::Plugin::ConfigLoader - Load config files of various types # by default myapp.* will be loaded # you can specify a file if you'd like - __PACKAGE__->config( file = > 'config.yaml' ); - + __PACKAGE__->config( file = > 'config.yaml' ); =head1 DESCRIPTION @@ -71,9 +71,32 @@ sub setup { } } + $c->finalize_config; + $c->NEXT::setup( @_ ); } +=head2 finalize_config + +This method is called after the config file is loaded. It can be +used to implement tuning of config values that can only be done +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. + +=cut + +sub finalize_config { + my $c = shift; + my $v = Data::Visitor::Callback->new( + plain_value => sub { s[^__HOME__/(.+)$][ $c->path_to($1) ]e } + ); + $v->visit( $c->config ); +} + =head1 AUTHOR =over 4 @@ -82,6 +105,17 @@ sub setup { =back +=head1 CONTRIBUTORS + +The following people have generously donated their time to the +development of this module: + +=over 4 + +=item * David Kamholz Edkamholz@cpan.orgE + +=back + =head1 COPYRIGHT AND LICENSE Copyright 2006 by Brian Cassidy