| 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
| |||||||||||
| 12 | |||||||||||
| 13 | 23 | ▶ | return {} unless defined $file; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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
| |||||||||||
| 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 | ||||||||||