NAME
Config::Tree::Env - Read configuration tree from environment variables
SYNOPSIS
# in Bash-like shell:
% CONFIG_FOO__BAR=3 perl script.pl
% CONFIG_FOO='{bar: 3}' perl script.pl; # same thing
# in script.pl:
use Config::Tree::Env;
my $conf = Config::Tree::Env->new(
# schema => ...,
# include_path_re => qr/.../,
# exclude_path_re => qr/.../,
# env_path_separator => '__',
# env_prefix => 'CONFIG_',
# env_lowercase => 1,
# env_as_yaml => 1,
ro => 0,
);
my $val = $conf->get('/foo/bar'); # 3
$conf->cd('/foo');
$conf->set('bar', 10); # same as set('/foo/bar', 10);
DESCRIPTION
This module, CT::Env, construct config tree from environment variables. By default, only config variables beginning with CONFIG_
will be parsed (can be changed with env_prefix
property). By default, __
in environment variable's names will be regarded as path separator (can be changed with env_path_separator
property). Also, by default, environment variable's name will be converted to lowercase (can be prevented by setting env_lowercase
property to 0). So, environment variable CONFIG_FOO__BAR
will become /foo/bar
while CONFIG_FOO_BAR
will become /foo_bar
and FOO_BAR
will be ignored.
ATTRIBUTES
METHODS
new(%args)
Construct a new Config::Tree::Env object. Arguments.
exclude_path_re
. Optional. When set, config path matching the regex will not be retrieved. See also:include_path_re
.include_path_re
. Optional. When set, only config path matching the regex will be retrieved. Takes precedence overexclude_path_re
.schema
. Optional. When specified, after the tree is retrieved, it will be validated against this schema using Data::Schema.env_path_separator
. Optional. What string to assume as path separator. Default is__
(two underscores). If you do not want path splitting, set this to empty string.env_prefix
. Optional. Default isCONFIG_
. What string to use as prefix. Only variables matching the prefix will be parsed. Setting this to empty string means all environment variables will be parsed and imported into config tree!env_lowercase
. Optional. Whether to convert environment variable's name to lowercase. Default is 1.env_as_yaml
. Optional. Whether to assume environment variable's value as YAML. Default is 1.
set($path, $val)
Does nothing.
save()
Does nothing.
SEE ALSO
Data::Schema, Config::Tree::Base
AUTHOR
Steven Haryanto, <stevenharyanto at gmail.com>
COPYRIGHT & LICENSE
Copyright 2009 Steven Haryanto, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.