Activator
view release on metacpan or search on metacpan
lib/Catalyst/Plugin/Activator/Config.pm view on Meta::CPAN
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<config()> section.
=cut
sub setup {
my $c = shift;
my @files = $c->find_files;
my $cfg = Config::Any->load_files(
{ files => \@files,
filter => \&_fix_syntax,
use_ext => 1,
driver_args => $c->config->{ 'Plugin::ConfigLoader' }->{ driver }
|| {},
}
);
# 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 ( @main, @locals );
for ( sort keys %configs ) {
if ( m{$local_suffix\.}ms ) {
push @locals, $_;
}
else {
push @main, $_;
}
}
# load all the normal cfgs, then the local cfgs last so they can override
# normal cfgs
$c->load_config( { $_ => $configs{ $_ } } ) for @main, @locals;
$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 ) = %$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.
It returns an array of paths (up to the filename less the extension) to pass to
L<Config::Any|Config::Any> for loading.
=cut
sub find_files {
my $c = shift;
my ( $path, $extension ) = $c->get_config_path;
my $suffix = $c->get_config_local_suffix;
my @extensions = @{ Config::Any->extensions };
my @files;
if ( $extension ) {
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;
}
=head2 get_config_path
This method determines the path, filename prefix and file extension to be used
for config loading. It returns the path (up to the filename less the
extension) to check and the specific extension to use (if it was specified).
The order of preference is specified as:
=over 4
=item * C<$ENV{ MYAPP_CONFIG }>
=item * C<$ENV{ CATALYST_CONFIG }>
=item * C<$c-E<gt>config-E<gt>{ 'Plugin::ConfigLoader' }-E<gt>{ file }>
=item * C<$c-E<gt>path_to( $application_prefix )>
=back
If either of the first two user-specified options are directories, the
application prefix will be added on to the end of the path.
=cut
sub get_config_path {
my $c = shift;
( run in 0.677 second using v1.01-cache-2.11-cpan-39bf76dae61 )