| 1 | package Config::MVP::Reader 2.200015; | ||||||||||||||||||||
| 2 | # ABSTRACT: object to read config from storage into an assembler | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 2 | ▶ | use Config::MVP::Assembler; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use Cwd (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | #pod =head1 SYNOPSIS | ||||||||||||||||||||
| 10 | #pod | ||||||||||||||||||||
| 11 | #pod use Config::MVP::Reader::YAML; # this doesn't really exist | ||||||||||||||||||||
| 12 | #pod | ||||||||||||||||||||
| 13 | #pod my $reader = Config::MVP::Reader::YAML->new; | ||||||||||||||||||||
| 14 | #pod | ||||||||||||||||||||
| 15 | #pod my $sequence = $reader->read_config('/etc/foobar.yml'); | ||||||||||||||||||||
| 16 | #pod | ||||||||||||||||||||
| 17 | #pod =head1 DESCRIPTION | ||||||||||||||||||||
| 18 | #pod | ||||||||||||||||||||
| 19 | #pod A Config::MVP::Reader exists to read configuration data from storage (like a | ||||||||||||||||||||
| 20 | #pod file) and convert that data into instructions to a L<Config::MVP::Assembler>, | ||||||||||||||||||||
| 21 | #pod which will in turn convert them into a L<Config::MVP::Sequence>, the final | ||||||||||||||||||||
| 22 | #pod product. | ||||||||||||||||||||
| 23 | #pod | ||||||||||||||||||||
| 24 | #pod =attr add_cwd_to_lib | ||||||||||||||||||||
| 25 | #pod | ||||||||||||||||||||
| 26 | #pod If true (which it is by default) then the current working directly will be | ||||||||||||||||||||
| 27 | #pod locally added to C<@INC> during config loading. This helps deal with changes | ||||||||||||||||||||
| 28 | #pod made in Perl v5.26.1. | ||||||||||||||||||||
| 29 | #pod | ||||||||||||||||||||
| 30 | #pod =cut | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 2 | has add_cwd_to_lib => ( | |||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||
| 34 | isa => 'Bool', | ||||||||||||||||||||
| 35 | default => 1, | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | #pod =method read_config | ||||||||||||||||||||
| 39 | #pod | ||||||||||||||||||||
| 40 | #pod my $sequence = $reader->read_config($location, \%arg); | ||||||||||||||||||||
| 41 | #pod | ||||||||||||||||||||
| 42 | #pod This method is passed a location, which has no set meaning, but should be the | ||||||||||||||||||||
| 43 | #pod mechanism by which the Reader is told how to locate configuration. It might be | ||||||||||||||||||||
| 44 | #pod a file name, a hashref of parameters, a DBH, or anything else, depending on the | ||||||||||||||||||||
| 45 | #pod needs of the specific Reader subclass. | ||||||||||||||||||||
| 46 | #pod | ||||||||||||||||||||
| 47 | #pod It is also passed a hashref of arguments, of which there is only one valid | ||||||||||||||||||||
| 48 | #pod argument: | ||||||||||||||||||||
| 49 | #pod | ||||||||||||||||||||
| 50 | #pod assembler - the Assembler object into which to read the config | ||||||||||||||||||||
| 51 | #pod | ||||||||||||||||||||
| 52 | #pod If no assembler argument is passed, one will be constructed by calling the | ||||||||||||||||||||
| 53 | #pod Reader's C<build_assembler> method. | ||||||||||||||||||||
| 54 | #pod | ||||||||||||||||||||
| 55 | #pod Subclasses should generally not override C<read_config>, but should instead | ||||||||||||||||||||
| 56 | #pod implement a C<read_into_assembler> method, described below. If a subclass | ||||||||||||||||||||
| 57 | #pod I<does> override C<read_config> it should take care to respect the | ||||||||||||||||||||
| 58 | #pod C<add_cwd_to_lib> attribute, above. | ||||||||||||||||||||
| 59 | #pod | ||||||||||||||||||||
| 60 | #pod =cut | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 4 | ▶ | sub read_config { | ||||||||||||||||||
|
Subroutine
read_config: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||
| 63 | 4 | my ($self, $location, $arg) = @_; | |||||||||||||||||||
| 64 | 4 | ▶ | $arg ||= {}; | ||||||||||||||||||
|
Condition100%2/2
$arg ||= {}
MC/DC100%1/1
$arg ||= {}
$arg
Truth table100%2/2
A
A= $arg
| |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 4 | ▶ | $self = $self->new unless blessed $self; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 4 | ▶ | my $assembler = $arg->{assembler} || $self->build_assembler; | ||||||||||||||||||
|
Condition66%2/3
$arg->{'assembler'} || $self->build_assembler
MC/DC0%0/2
$arg->{'assembler'} || $self->build_assembler
$arg->{'assembler'}
$self->build_assembler
Truth table66%2/3
A || B
A= $arg->{'assembler'}B= $self->build_assembler
| |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | { | ||||||||||||||||||||
| 71 | 4 | local @INC = @INC; | |||||||||||||||||||
| 72 | 4 | ▶ | if ($self->add_cwd_to_lib) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 4 | my $cwd = Cwd::getcwd(); | |||||||||||||||||||
| 74 | 4 | ▶ | push @INC, $cwd unless grep {; $_ eq $cwd } @INC; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | 4 | $self->read_into_assembler($location, $assembler); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 4 | return $assembler->sequence; | |||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | #pod =method read_into_assembler | ||||||||||||||||||||
| 83 | #pod | ||||||||||||||||||||
| 84 | #pod This method should not be called directly. It is called by C<read_config> with | ||||||||||||||||||||
| 85 | #pod the following parameters: | ||||||||||||||||||||
| 86 | #pod | ||||||||||||||||||||
| 87 | #pod my $sequence = $reader->read_into_assembler( $location, $assembler ); | ||||||||||||||||||||
| 88 | #pod | ||||||||||||||||||||
| 89 | #pod The method should read the configuration found at C<$location> and use it to | ||||||||||||||||||||
| 90 | #pod instruct the C<$assembler> (a L<Config::MVP::Assembler>) what configuration to | ||||||||||||||||||||
| 91 | #pod perform. | ||||||||||||||||||||
| 92 | #pod | ||||||||||||||||||||
| 93 | #pod The default implementation of this method will throw an exception complaining | ||||||||||||||||||||
| 94 | #pod that it should have been implemented by a subclass. | ||||||||||||||||||||
| 95 | #pod | ||||||||||||||||||||
| 96 | #pod =cut | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | 0 | ▶ | sub read_into_assembler { | ||||||||||||||||||
|
Subroutine
read_into_assembler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 99 | 0 | confess 'required method read_into_assembler unimplemented' | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | #pod =method build_assembler | ||||||||||||||||||||
| 103 | #pod | ||||||||||||||||||||
| 104 | #pod If no Assembler is provided to C<read_config>'s C<assembler> parameter, this | ||||||||||||||||||||
| 105 | #pod method will be called on the Reader to construct one. | ||||||||||||||||||||
| 106 | #pod | ||||||||||||||||||||
| 107 | #pod It must return a Config::MVP::Assembler object, and by default will return an | ||||||||||||||||||||
| 108 | #pod entirely generic one. | ||||||||||||||||||||
| 109 | #pod | ||||||||||||||||||||
| 110 | #pod =cut | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | 0 | ▶ | sub build_assembler { Config::MVP::Assembler->new; } | ||||||||||||||||||
|
Subroutine
build_assembler: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | 2 | ▶ | no Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 115 | 2 | 1; | |||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||