MVP/Reader/Finder.pm

filter: Statementstmt 91.8% 45 / 49 Branchbran 50.0% 9 / 18 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 76.9% 10 / 13 Podpod 100% 4 / 4 totaltotal 76.0% 70 / 92 CC 13 SCAR 16.8
CC
13
Cov
78%
__ANON__
12.0
read_config
7.5
_which_reader
7.1
CRAP 5.4
« MVP/Assembler/WithBundles.pm ↑ Summary MVP/Reader.pm »
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
BranchTrueFalseTotal
unless $pkg->isa("Moose::Object") 2 3 5
67 3 ▶ next unless $pkg->does('Config::MVP::Reader::Findable');
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg->does("Config::MVP::Reader::Findable") 2 1 3
68  
69 1 my $location = $pkg->refined_location($location);
70  
71 1 ▶ next unless defined $location;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $location 0 1 1
72  
73 1 push @options, [ $pkg, $location ];
74 }
75  
76 1 ▶ Config::MVP::Error->throw("no viable configuration could be found")
Branch: 1 branch
BranchTrueFalseTotal
unless @options 0 1 1
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
BranchTrueFalseTotal
if @options > 1 0 1 1
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
BranchTrueFalseTotal
unless builtin::blessed($self) 1 0 1
97 1 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
01
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
98  
99 1 ▶ local $arg->{assembler} = $arg->{assembler} || $self->build_assembler;
Condition33%1/3
$arg->{'assembler'} || $self->build_assembler
l!l&&r!l&&!r
010
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
unless $_ =~ /^no viable configuration/ 0 0 0
107 0 ▶ die $_ unless defined (my $handler = $self->if_none);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $handler = $self->if_none) 0 0 0
108 0 $instead = $self->$handler($location, $arg);
109 1 };
110  
111 1 ▶ return $instead unless $which;
Branch: 1 branch
BranchTrueFalseTotal
unless $which 0 1 1
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__
« MVP/Assembler/WithBundles.pm ↑ Summary MVP/Reader.pm »