From: David Kamholz Date: Tue, 28 Feb 2006 11:08:01 +0000 (+0000) Subject: update ConfigLoader in Catalyst dist X-Git-Tag: 5.7099_04~688 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=2fb22e6e6967ab08a4ea3ca996378e59fe2de2c6 update ConfigLoader in Catalyst dist --- 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 diff --git a/lib/Catalyst/Plugin/ConfigLoader/YAML.pm b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm index 6acc3a9..88683dc 100644 --- a/lib/Catalyst/Plugin/ConfigLoader/YAML.pm +++ b/lib/Catalyst/Plugin/ConfigLoader/YAML.pm @@ -3,8 +3,6 @@ package Catalyst::Plugin::ConfigLoader::YAML; use strict; use warnings; -use File::Slurp; - =head1 NAME Catalyst::Plugin::ConfigLoader::YAML - Load YAML config files @@ -46,7 +44,9 @@ sub load { return YAML::LoadFile( $file ); } else { - my $content = read_file( $file ); + open( my $fh, $file ) or die $!; + my $content = do { local $/; <$fh> }; + close $fh; return YAML::Syck::Load( $content ); } }