Layered/Source/ConfigAny.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 66.6% 4 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 88.2% 30 / 34 CC 4 SCAR 9.4
CC
4
Cov
89%
get_config
4.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.6
« Layered/Source/Getopt.pm ↑ Summary Layered/Source.pm »
1 package Config::Layered::Source::ConfigAny;
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use base 'Config::Layered::Source';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 23 ▶sub get_config {
Subroutine get_config: called CC=4 SCAR=14.2
Pod undocumented
8 23 my ( $self ) = @_;
9  
10 23 my $file = $self->args->{file};
11 23 ▶ $file = $self->layered->{file} unless $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 23 0 23
12  
13 23 ▶ return {} unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 19 4 23
14  
15 4 my $config = Config::Any->load_stems( {
16 stems => [ $file ],
17 use_ext => 1,
18 });
19
20 4 return $config->[0]->{ (keys %{$config->[0]})[0] }
21 4 ▶ if @{$config} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$config;} == 1 4 0 4
22  
23 0 return {}; # If we couldn't load a config file.
24 }
25  
26 2 1;
27  
28 =head1 NAME
29  
30 Config::Layered::Source::ConfigAny - The Configuration File Source
31  
32 =head1 DESCRIPTION
33  
34 The ConfigAny source provices access to running ConfigAny on a given
35 file stem.
36  
37 =head1 EXAMPLE
38  
39 my $config = Config::Layered->load_config(
40 sources => [ 'ConfigAny' => { file => "/etc/myapp" } ],
41 default => {
42 foo => "bar",
43 blee => "baz",
44 bax => {
45 chicken => "eggs",
46 }
47 }
48 );
49  
50  
51 Provided a file C</etc/myapp> with the following content:
52  
53 foo: this
54 bax:
55 chicken: no-eggs
56 pork: chops
57  
58 The following data structure in C<$config> would be the result:
59  
60 {
61 foo => "this",
62 blee => "baz",
63 bax => {
64 chicken => "no-eggs",
65 pork => "chops",
66 }
67
68 =head1 SOURCE ARGUMENTS
69  
70 =over 4
71  
72 =item * file is a string which will be passed to Config::Any as a
73 file stem.
74  
75 =back
76  
77 =head1 GLOBAL ARGUMENTS
78  
79 =over 4
80  
81 =item * file is a string which will be passed to Config::Any as a
82 file stem -- file as a source argument will take precedence.
83  
84 =back
85  
86 =cut
« Layered/Source/Getopt.pm ↑ Summary Layered/Source.pm »