X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FConfigLoader.pm;h=374dc41db4fc4698ab2649fcd8e2cfc90ba86b57;hb=ba19b7b74c19b393daa1442833961d1e7632ca06;hp=fc68afb755633eb41b0c239616a7ea99f79a2b26;hpb=da18b9254f99fad1eb0b3a420f2ababbb8280d5d;p=catagits%2FCatalyst-Plugin-ConfigLoader.git diff --git a/lib/Catalyst/Plugin/ConfigLoader.pm b/lib/Catalyst/Plugin/ConfigLoader.pm index fc68afb..374dc41 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.07'; =head1 NAME @@ -23,24 +23,28 @@ Catalyst::Plugin::ConfigLoader - Load config files of various types # ConfigLoader should be first in your list so # other plugins can get the config information use Catalyst qw( ConfigLoader ... ); - + # by default myapp.* will be loaded # you can specify a file if you'd like __PACKAGE__->config( file = > 'config.yaml' ); =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,16 +62,16 @@ sub setup { push @files, $path; } else { - push @files, "$path.$_" for @extensions; + @files = map { ( "$path.$_", "${path}_local.$_" ) } @extensions; } for( @files ) { next unless -f $_; my $config = $loader->load( $_ ); - if( $config ) { - $c->config( $config ); - last; - } + + _fix_syntax( $config ); + + $c->config( $config ) if $config; } } @@ -84,8 +88,10 @@ 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 @@ -101,6 +107,23 @@ sub finalize_config { $v->visit( $c->config ); } +sub _fix_syntax { + my $config = shift; + my @components = ( + map +{ + prefix => $_ eq 'Component' ? '' : $_ . '::', + values => delete $config->{ lc $_ } || delete $config->{ $_ } + }, qw( Component Model View Controller ) + ); + + foreach my $comp ( @components ) { + my $prefix = $comp->{ prefix }; + foreach my $element ( keys %{ $comp->{ values } } ) { + $config->{ "$prefix$element" } = $comp->{ values }->{ $element }; + } + } +} + =head1 AUTHOR =over 4