use strict;
use warnings;
+
use Config::Any;
use NEXT;
use Data::Visitor::Callback;
-our $VERSION = '0.13';
+
+our $VERSION = '0.14';
=head1 NAME
=cut
sub setup {
- my $c = shift;
-
+ my $c = shift;
my @files = $c->find_files;
- my $cfg = Config::Any->load_stems({stems => \@files, filter => \&_fix_syntax});
-
- for my $ref (@$cfg) {
- my ($file, $config) = each %$ref;
- $c->config($config);
- $c->log->debug( qq(Loaded Config "$file") )
- if $c->debug;
+ my $cfg = Config::Any->load_files( {
+ files => \@files,
+ filter => \&_fix_syntax,
+ use_ext => 1
+ } );
+
+ # 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, $_;
+ } else {
+ push @cfg, $_;
+ }
}
+
+ # load all the normal cfgs, then the local cfgs last so they can override
+ # normal cfgs
+ $c->load_config( $_ ) for @cfg, @localcfg;
$c->finalize_config;
$c->NEXT::setup( @_ );
}
+=head2 load_config
+
+This method handles loading the configuration data into the Catalyst
+context object. It does not return a value.
+
+=cut
+
+sub load_config {
+ my $c = shift;
+ my $ref = shift;
+
+ my( $file, $config ) = each %$ref;
+
+ $c->config( $config );
+ $c->log->debug( qq(Loaded Config "$file") )
+ if $c->debug;
+
+ return;
+}
+
=head2 find_files
This method determines the potential file paths to be used for config loading.
sub find_files {
my $c = shift;
- my ($path, $extension) = $c->get_config_path;
- my $suffix = $c->get_config_local_suffix;
+ my( $path, $extension ) = $c->get_config_path;
+ my $suffix = $c->get_config_local_suffix;
my @extensions = @{ Config::Any->extensions };
my @files;
if ($extension) {
next unless grep { $_ eq $extension } @extensions;
- push @files, $path;
+ push @files, $path, "${path}_${suffix}";
} else {
@files = map { ( "$path.$_", "${path}_${suffix}.$_" ) } @extensions;
}
+
@files;
}
=item * C<$c-E<gt>config-E<gt>{ config_local_suffix }>
-
=back
=cut
$v->visit( $c->config );
}
+=head1 AUTHOR
+
+=over 4
+
+=item * Brian Cassidy E<lt>bricas@cpan.orgE<gt>
+
+=back
+
+=head1 CONTRIBUTORS
+
+The following people have generously donated their time to the
+development of this module:
+
+=over 4
+
+=item * Joel Bernstein E<lt>rataxis@cpan.orgE<gt> - Rewrite to use L<Config::Any>
+
+=item * David Kamholz E<lt>dkamholz@cpan.orgE<gt> - L<Data::Visitor> integration
+
+=back
+
+Work to this module has been generously sponsored by:
+
+=over 4
+
+=item * Portugal Telecom L<http://www.sapo.pt/> - Work done by Joel Bernstein
+
+=back
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2006 by Brian Cassidy
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=head1 SEE ALSO
+
+=over 4
+
+=item * L<Catalyst>
+
+=item * L<Catalyst::Plugin::ConfigLoader::Manual>
+
+=item * L<Config::Any>
+
+=back
+
+=cut
+
1;