line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Layered::Source::ConfigAny; |
2
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
3
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
4
|
2
|
|
|
2
|
|
1886
|
use Config::Any; |
|
2
|
|
|
|
|
23827
|
|
|
2
|
|
|
|
|
72
|
|
5
|
2
|
|
|
2
|
|
20
|
use base 'Config::Layered::Source'; |
|
2
|
|
|
|
|
49
|
|
|
2
|
|
|
|
|
1450
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub get_config { |
8
|
23
|
|
|
23
|
0
|
32
|
my ( $self ) = @_; |
9
|
|
|
|
|
|
|
|
10
|
23
|
|
|
|
|
68
|
my $file = $self->args->{file}; |
11
|
23
|
50
|
|
|
|
91
|
$file = $self->layered->{file} unless $file; |
12
|
|
|
|
|
|
|
|
13
|
23
|
100
|
|
|
|
452
|
return {} unless defined $file; |
14
|
|
|
|
|
|
|
|
15
|
4
|
|
|
|
|
35
|
my $config = Config::Any->load_stems( { |
16
|
|
|
|
|
|
|
stems => [ $file ], |
17
|
|
|
|
|
|
|
use_ext => 1, |
18
|
|
|
|
|
|
|
}); |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
325
|
return $config->[0]->{ (keys %{$config->[0]})[0] } |
|
4
|
|
|
|
|
23
|
|
21
|
4
|
50
|
|
|
|
45350
|
if @{$config} == 1; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return {}; # If we couldn't load a config file. |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
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 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 |