| 1 | package Config::MVP::Reader::Finder 2.200015; | ||||||||||||||||||||
| 2 | # ABSTRACT: a reader that finds an appropriate file | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | extends 'Config::MVP::Reader'; | |||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | #pod =head1 DESCRIPTION | ||||||||||||||||||||
| 8 | #pod | ||||||||||||||||||||
| 9 | #pod The Finder reader multiplexes many other readers that implement the | ||||||||||||||||||||
| 10 | #pod L<Config::MVP::Reader::Findable> role. It uses L<Module::Pluggable> to search | ||||||||||||||||||||
| 11 | #pod for modules, limits them to objects implementing the Findable role, and then | ||||||||||||||||||||
| 12 | #pod selects the those which report that they are able to read a configuration file | ||||||||||||||||||||
| 13 | #pod found in the config root directory. If exactly one findable configuration | ||||||||||||||||||||
| 14 | #pod reader finds a file, it is used to read the file and the configuration sequence | ||||||||||||||||||||
| 15 | #pod is returned. Otherwise, an exception is raised. | ||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||
| 17 | #pod Config::MVP::Reader::Finder's C<build_assembler> method will decline a new | ||||||||||||||||||||
| 18 | #pod assembler, so if none was passed to C<read_config>, the Findable reader to | ||||||||||||||||||||
| 19 | #pod which reading is delegated will be responsible for building the assembler, | ||||||||||||||||||||
| 20 | #pod unless a Finder subclass overrides C<build_assembler> to set a default across | ||||||||||||||||||||
| 21 | #pod all possible delegates. | ||||||||||||||||||||
| 22 | #pod | ||||||||||||||||||||
| 23 | #pod =cut | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 1 | ▶ | use Config::MVP::Error; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 1 | ▶ | use Module::Pluggable::Object; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use Try::Tiny; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | #pod =method default_search_path | ||||||||||||||||||||
| 30 | #pod | ||||||||||||||||||||
| 31 | #pod This is the default search path used to find configuration readers. This | ||||||||||||||||||||
| 32 | #pod method should return a list, and by default returns: | ||||||||||||||||||||
| 33 | #pod | ||||||||||||||||||||
| 34 | #pod qw( Config::MVP::Reader ) | ||||||||||||||||||||
| 35 | #pod | ||||||||||||||||||||
| 36 | #pod =cut | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | ▶ | sub default_search_path { | ||||||||||||||||||
|
Subroutine
default_search_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 39 | 1 | return qw(Config::MVP::Reader) | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | our @DONT_FIND; | |||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | has _module_pluggable_object => ( | ||||||||||||||||||||
| 45 | is => 'ro', | ||||||||||||||||||||
| 46 | init_arg => undef, | ||||||||||||||||||||
| 47 | 1 | ▶ | default => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | 1 | my ($self) = @_; | |||||||||||||||||||
| 49 | 1 | Module::Pluggable::Object->new( | |||||||||||||||||||
| 50 | search_path => [ $self->default_search_path ], | ||||||||||||||||||||
| 51 | inner => 0, | ||||||||||||||||||||
| 52 | require => 1, | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | # This facility here entirely for testing. -- rjbs, 2014-07-02 | ||||||||||||||||||||
| 55 | except => \@DONT_FIND, | ||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||
| 57 | }, | ||||||||||||||||||||
| 58 | 1 | ); | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | ▶ | sub _which_reader { | ||||||||||||||||||
|
Subroutine
_which_reader: called CC=7 SCAR=19.7
| |||||||||||||||||||||
| 61 | 1 | my ($self, $location) = @_; | |||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 1 | my @options; | |||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 1 | for my $pkg ($self->_module_pluggable_object->plugins) { | |||||||||||||||||||
| 66 | 5 | ▶ | next unless $pkg->isa('Moose::Object'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 3 | ▶ | next unless $pkg->does('Config::MVP::Reader::Findable'); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | 1 | my $location = $pkg->refined_location($location); | |||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 1 | ▶ | next unless defined $location; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 1 | push @options, [ $pkg, $location ]; | |||||||||||||||||||
| 74 | } | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | 1 | ▶ | Config::MVP::Error->throw("no viable configuration could be found") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | unless @options; | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | # XXX: Improve this error message -- rjbs, 2010-05-24 | ||||||||||||||||||||
| 80 | 1 | ▶ | Config::MVP::Error->throw("multiple possible config plugins found") | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 81 | if @options > 1; | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | return { | ||||||||||||||||||||
| 84 | 1 | 'package' => $options[0][0], | |||||||||||||||||||
| 85 | 'location' => $options[0][1], | ||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 1 | has if_none => ( | |||||||||||||||||||
| 90 | is => 'ro', | ||||||||||||||||||||
| 91 | isa => 'Maybe[Str|CodeRef]', | ||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 1 | ▶ | sub read_config { | ||||||||||||||||||
|
Subroutine
read_config: called CC=5 SCAR=20.1
Pod
documented
| |||||||||||||||||||||
| 95 | 1 | my ($self, $location, $arg) = @_; | |||||||||||||||||||
| 96 | 1 | ▶ | $self = $self->new unless blessed($self); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 97 | 1 | ▶ | $arg ||= {}; | ||||||||||||||||||
|
Condition50%1/2
$arg ||= {}
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
| |||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 1 | ▶ | local $arg->{assembler} = $arg->{assembler} || $self->build_assembler; | ||||||||||||||||||
|
Condition33%1/3
$arg->{'assembler'} || $self->build_assembler
MC/DC0%0/2
$arg->{'assembler'} || $self->build_assembler
$arg->{'assembler'}
$self->build_assembler
Truth table33%1/3
A || B
A= $arg->{'assembler'}B= $self->build_assembler
| |||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 1 | my $which; | |||||||||||||||||||
| 102 | my $instead; | ||||||||||||||||||||
| 103 | 1 | ▶ | try { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 104 | 1 | $which = $self->_which_reader($location); | |||||||||||||||||||
| 105 | 0 | ▶ | } catch { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 106 | 0 | ▶ | die $_ unless $_ =~ /^no viable configuration/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 0 | ▶ | die $_ unless defined (my $handler = $self->if_none); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 108 | 0 | $instead = $self->$handler($location, $arg); | |||||||||||||||||||
| 109 | 1 | }; | |||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 1 | ▶ | return $instead unless $which; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | my $reader = $which->{package}->new({ | ||||||||||||||||||||
| 114 | 1 | add_cwd_to_lib => $self->add_cwd_to_lib, | |||||||||||||||||||
| 115 | }); | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 1 | return $reader->read_config( $which->{location}, $arg ); | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub build_assembler { } | ||||||||||||||||||
|
Subroutine
build_assembler: not called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | 0 | ▶ | sub read_into_assembler { | ||||||||||||||||||
|
Subroutine
read_into_assembler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 123 | 0 | confess "This method should never be called or reachable"; | |||||||||||||||||||
| 124 | } | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 1 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 127 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 128 | 1 | 1; | |||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||