File Coverage

blib/lib/Config/MVP/Reader/Findable/ByExtension.pm
Criterion Covered Total %
statement 13 13 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 4 4 100.0
pod 1 1 100.0
total 20 23 86.9


line stmt bran cond sub pod time code
1             package Config::MVP::Reader::Findable::ByExtension;
2             # ABSTRACT: a Findable Reader that looks for files by extension
3             $Config::MVP::Reader::Findable::ByExtension::VERSION = '2.200012';
4 1     1   10404 use Moose::Role;
  1         3  
  1         8  
5              
6             with qw(Config::MVP::Reader::Findable);
7              
8 1     1   5385 use File::Spec;
  1         2  
  1         125  
9              
10             #pod =method default_extension
11             #pod
12             #pod This method, B<which must be composed by classes including this role>, returns
13             #pod the default extension used by files in the format this reader can read.
14             #pod
15             #pod When the Finder tries to find configuration, it have a directory root and a
16             #pod basename. Each (Findable) reader that it tries in turn will look for a file
17             #pod F<basename.extension> in the root directory. If exactly one file is found,
18             #pod that file is read.
19             #pod
20             #pod =cut
21              
22             requires 'default_extension';
23              
24             #pod =method refined_location
25             #pod
26             #pod This role provides a default implementation of the
27             #pod L<C<refined_location>|Config::MVP::Reader::Findable/refined_location> method
28             #pod required by Config::MVP::Reader. It will return a filename based on the
29             #pod original location, if a file exists matching that location plus the reader's
30             #pod C<default_extension>.
31             #pod
32             #pod =cut
33              
34             sub refined_location {
35 1     1 1 4 my ($self, $location) = @_;
36              
37 1         6 my $candidate_name = "$location." . $self->default_extension;
38 1 50 33     34 return unless -r $candidate_name and -f _;
39 1         6 return $candidate_name;
40             }
41              
42 1     1   8 no Moose::Role;
  1         2  
  1         7  
43             1;
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             Config::MVP::Reader::Findable::ByExtension - a Findable Reader that looks for files by extension
54              
55             =head1 VERSION
56              
57             version 2.200012
58              
59             =head1 METHODS
60              
61             =head2 default_extension
62              
63             This method, B<which must be composed by classes including this role>, returns
64             the default extension used by files in the format this reader can read.
65              
66             When the Finder tries to find configuration, it have a directory root and a
67             basename. Each (Findable) reader that it tries in turn will look for a file
68             F<basename.extension> in the root directory. If exactly one file is found,
69             that file is read.
70              
71             =head2 refined_location
72              
73             This role provides a default implementation of the
74             L<C<refined_location>|Config::MVP::Reader::Findable/refined_location> method
75             required by Config::MVP::Reader. It will return a filename based on the
76             original location, if a file exists matching that location plus the reader's
77             C<default_extension>.
78              
79             =head1 AUTHOR
80              
81             Ricardo Signes <rjbs@cpan.org>
82              
83             =head1 COPYRIGHT AND LICENSE
84              
85             This software is copyright (c) 2021 by Ricardo Signes.
86              
87             This is free software; you can redistribute it and/or modify it under
88             the same terms as the Perl 5 programming language system itself.
89              
90             =cut