use Data::Visitor::Callback;
use Catalyst::Utils ();
-our $VERSION = '0.19';
+our $VERSION = '0.20';
=head1 NAME
# you can specify a file if you'd like
__PACKAGE__->config( 'Plugin::ConfigLoader' => { file => 'config.yaml' } );
+ In the file, assuming it's in YAML format:
+
+ foo: bar
+
+ Accessible through the context object, or the class itself
+
+ $c->config->{foo} # bar
+ MyApp->config->{foo} # bar
+
=head1 DESCRIPTION
This module will attempt to load find and load a configuration
|| {},
}
);
+ # map the array of hashrefs to a simple hash
+ my %configs = map { %$_ } @$cfg;
# split the responses into normal and local cfg
my $local_suffix = $c->get_config_local_suffix;
- my ( @cfg, @localcfg );
- for ( @$cfg ) {
- if ( ( keys %$_ )[ 0 ] =~ m{ $local_suffix \. }xms ) {
- push @localcfg, $_;
+ my ( @main, @locals );
+ for ( sort keys %configs ) {
+ if ( m{$local_suffix\.}ms ) {
+ push @locals, $_;
}
else {
- push @cfg, $_;
+ push @main, $_;
}
}
# load all the normal cfgs, then the local cfgs last so they can override
# normal cfgs
- $c->load_config( $_ ) for @cfg, @localcfg;
+ $c->load_config( { $_ => $configs{ $_ } } ) for @main, @locals;
$c->finalize_config;
$c->NEXT::setup( @_ );
my $c = shift;
my $ref = shift;
- my ( $file, $config ) = each %$ref;
+ my ( $file, $config ) = %$ref;
$c->config( $config );
$c->log->debug( qq(Loaded Config "$file") )
my @files;
if ( $extension ) {
- next unless grep { $_ eq $extension } @extensions;
+ die "Unable to handle files with the extension '${extension}'"
+ unless grep { $_ eq $extension } @extensions;
( my $local = $path ) =~ s{\.$extension}{_$suffix.$extension};
push @files, $path, $local;
}
else {
@files = map { ( "$path.$_", "${path}_${suffix}.$_" ) } @extensions;
}
-
@files;
}
# deprecation notice
if ( exists $c->config->{ file } ) {
$c->log->warn(
- q("file" config parameter has been deprecated in favor of "$c->config->{ 'Plugin::ConfigLoader' }->{ file }")
+ q(*** "file" config parameter has been deprecated in favor of "$c->config->{ 'Plugin::ConfigLoader' }->{ file }")
);
+ sleep( 3 );
}
my $appname = ref $c || $c;
# deprecation notice
if ( exists $c->config->{ config_local_suffix } ) {
$c->log->warn(
- q("config_local_suffix" config parameter has been deprecated in favor of "$c->config->{ 'Plugin::ConfigLoader' }->{ config_local_suffix }")
+ q(*** "config_local_suffix" config parameter has been deprecated in favor of "$c->config->{ 'Plugin::ConfigLoader' }->{ config_local_suffix }")
);
+ sleep( 3 );
}
my $appname = ref $c || $c;
=head1 COPYRIGHT AND LICENSE
-Copyright 2007 by Brian Cassidy
+Copyright 2008 by Brian Cassidy
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.