require => 1;\r
use Data::Visitor::Callback;\r
\r
-our $VERSION = '0.06';\r
+our $VERSION = '0.08';\r
\r
=head1 NAME\r
\r
# ConfigLoader should be first in your list so\r
# other plugins can get the config information\r
use Catalyst qw( ConfigLoader ... );\r
- \r
+ \r
# by default myapp.* will be loaded\r
# you can specify a file if you'd like\r
- __PACKAGE__->config( file = > 'config.yaml' ); \r
+ __PACKAGE__->config( file => 'config.yaml' ); \r
\r
=head1 DESCRIPTION\r
\r
=cut\r
\r
sub setup {\r
- my $c = shift;\r
- my $path = $c->config->{ file } || $c->path_to( Catalyst::Utils::appprefix( ref $c || $c ) );\r
-\r
- my( $extension ) = ( $path =~ /\.(.{1,4})$/ );\r
+ my $c = shift;\r
+ my( $path, $extension ) = $c->get_config_path;\r
\r
for my $loader ( $c->_config_loaders ) {\r
my @files;\r
for( @files ) {\r
next unless -f $_;\r
my $config = $loader->load( $_ );\r
+\r
+ $c->log->debug( "Loaded Config $_" ) if $c->debug;\r
+ _fix_syntax( $config );\r
$c->config( $config ) if $config;\r
}\r
}\r
$v->visit( $c->config );\r
}\r
\r
+=head2 get_config_path\r
+\r
+This method determines the path, filename prefix and file extension to be used\r
+for config loading. It returns the path (up to the filename less the\r
+extension) to check and the specific extension to use (if it was specified).\r
+\r
+The order of preference is specified as:\r
+\r
+=over 4\r
+\r
+=item * C<$ENV{ MYAPP_CONFIG }>\r
+\r
+=item * C<$c->config->{ file }>\r
+\r
+=item * C<$c->path_to( $application_prefix )>\r
+\r
+=back\r
+\r
+If either of the first two user-specified options are directories, the\r
+application prefix will be added on to the end of the path.\r
+\r
+=cut\r
+\r
+sub get_config_path {\r
+ my $c = shift;\r
+ my $appname = ref $c || $c;\r
+ my $prefix = Catalyst::Utils::appprefix( $appname );\r
+ my $path = $ENV{ Catalyst::Utils::class2env( $appname ) . '_CONFIG' }\r
+ || $c->config->{ file }\r
+ || $c->path_to( $prefix );\r
+\r
+ my( $extension ) = ( $path =~ /\.(.{1,4})$/ );\r
+ \r
+ if( -d $path ) {\r
+ $path =~ s/[\/\\]$//;\r
+ $path .= "/$prefix";\r
+ }\r
+ \r
+ return( $path, $extension );\r
+}\r
+\r
+sub _fix_syntax {\r
+ my $config = shift;\r
+ my @components = (\r
+ map +{\r
+ prefix => $_ eq 'Component' ? '' : $_ . '::',\r
+ values => delete $config->{ lc $_ } || delete $config->{ $_ }\r
+ }, qw( Component Model View Controller )\r
+ );\r
+\r
+ foreach my $comp ( @components ) {\r
+ my $prefix = $comp->{ prefix };\r
+ foreach my $element ( keys %{ $comp->{ values } } ) {\r
+ $config->{ "$prefix$element" } = $comp->{ values }->{ $element };\r
+ }\r
+ }\r
+}\r
+\r
=head1 AUTHOR\r
\r
=over 4 \r