Config-MVP
view release on metacpan or search on metacpan
lib/Config/MVP/Reader/Finder.pm view on Meta::CPAN
package Config::MVP::Reader::Finder 2.200013;
# ABSTRACT: a reader that finds an appropriate file
use Moose;
extends 'Config::MVP::Reader';
#pod =head1 DESCRIPTION
#pod
#pod The Finder reader multiplexes many other readers that implement the
#pod L<Config::MVP::Reader::Findable> role. It uses L<Module::Pluggable> to search
#pod for modules, limits them to objects implementing the Findable role, and then
#pod selects the those which report that they are able to read a configuration file
#pod found in the config root directory. If exactly one findable configuration
#pod reader finds a file, it is used to read the file and the configuration sequence
#pod is returned. Otherwise, an exception is raised.
#pod
#pod Config::MVP::Reader::Finder's C<build_assembler> method will decline a new
#pod assembler, so if none was passed to C<read_config>, the Findable reader to
#pod which reading is delegated will be responsible for building the assembler,
#pod unless a Finder subclass overrides C<build_assembler> to set a default across
#pod all possible delegates.
#pod
#pod =cut
use Config::MVP::Error;
use Module::Pluggable::Object;
use Try::Tiny;
#pod =method default_search_path
#pod
#pod This is the default search path used to find configuration readers. This
#pod method should return a list, and by default returns:
#pod
#pod qw( Config::MVP::Reader )
#pod
#pod =cut
sub default_search_path {
return qw(Config::MVP::Reader)
}
our @DONT_FIND;
has _module_pluggable_object => (
is => 'ro',
init_arg => undef,
default => sub {
my ($self) = @_;
Module::Pluggable::Object->new(
search_path => [ $self->default_search_path ],
inner => 0,
require => 1,
# This facility here entirely for testing. -- rjbs, 2014-07-02
except => \@DONT_FIND,
);
},
);
sub _which_reader {
my ($self, $location) = @_;
my @options;
for my $pkg ($self->_module_pluggable_object->plugins) {
next unless $pkg->isa('Moose::Object');
next unless $pkg->does('Config::MVP::Reader::Findable');
my $location = $pkg->refined_location($location);
next unless defined $location;
push @options, [ $pkg, $location ];
}
Config::MVP::Error->throw("no viable configuration could be found")
unless @options;
# XXX: Improve this error message -- rjbs, 2010-05-24
Config::MVP::Error->throw("multiple possible config plugins found")
if @options > 1;
return {
'package' => $options[0][0],
'location' => $options[0][1],
};
}
( run in 0.797 second using v1.01-cache-2.11-cpan-39bf76dae61 )