Config::Layered::Source::ENV - The Environment Variable Source
The ENV source provides configuration through environment variables.
For each top-level key in the default data structure, it checks for the environment variable CONFIG_$KEY where $KEY is the name of the key used in the default data structure.
CONFIG_$KEY
my $config = Config::Layered->load_config( default => { foo => "bar", blee => "baz", bax => { chicken => "eggs", } } );
With the above configuration, the following keys will be checked:
CONFIG_FOO
CONFIG_BLEE
CONFIG_BAX
The following would *NOT* be checked:
CONFIG_CHICKEN
Given the above default data structure, a command run as CONFIG_FOO="Hello World" ./myprogram would result in a $config structure like this:
CONFIG_FOO="Hello World" ./myprogram
$config
{ foo => "Hello World", blee => "baz", bax => { chicken => "eggs", }
params is an array ref of keys to check Default: Keys of the default data structure.
prefix is a word prepended to your key that is used to check $ENV{$prefix . "_" . uc($key) }.
$ENV{$prefix . "_" . uc($key) }
Example:
Config::Layered->load_config( sources => [ 'ENV' => { prefix => "MYAPP", params => [qw( bar blee )] } ], default => { debug => 0, verbose => 1 }, );
The following keys would be checked:
MYAPP_BAR
MYAPP_BLEE
MYAPP_DEBUG
MYAPP_VERBOSE
To install Config::Layered, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Config::Layered
CPAN shell
perl -MCPAN -e shell install Config::Layered
For more information on module installation, please visit the detailed CPAN module installation guide.