NAME
Config::Tree::YAMLHashDir - Read configuration tree from a directory of YAML files containing (derivative) hash
SYNOPSIS
# in confdir/templates/server:
services:
# for security, the default setting for all servers is to have no services
# enabled, except for dns resolver.
http: No
ftp: No
dns_server: No
dns_resolver: Yes
mysql: No
# in confdir/templates/http_server:
- server
- services:
http: Yes
# in confdir/templates/dns_server:
- server
- services:
dns_server: Yes
# in confdir/templates/powerdns_server:
- dns_server
- services:
# we are using mysql backend for powerdns, so we need mysql service too
mysql: Yes
# in confdir/dns1:
- templates/powerdns_server
- templates/http_server
- ip: 1.2.3.4
# in confdir/dns2:
- templates/dns_server
- ip: 1.2.3.5
# in script.pl:
use Config::Tree::YAMLHashDir;
my $conf = Config::Tree::YAMLHashDir->new(
path => '/path/to/confdir',
#see Config::Tree::Dir for other options
);
$conf->get('/dns2/ip'); # 1.2.3.5
$conf->get('/dns2/services'); # {http=>0, ftp=>0, dns_server=>1, dns_resolver=>1. mysql=>0}
$conf->get('/dns1/services'); # {http=>0, ftp=>0, dns_server=>1, dns_resolver=>1, mysql=>1}
DESCRIPTION
CT::YAMLHashDir is a subclass of CT::Dir. All files in config dir must be YAML files, and the YAML documents must be hashes. However, if YAML document is an array, then it is further parsed like this: for each element, if element is string than it is assumed to be the config path to another YAML document, otherwise it must be hash. All resulting hashes will be merged together using Data::PrefixMerge.
The idea is to allow writing config files that are derived (a la OO) from other config files. See the above example.
ATTRIBUTES
METHODS
new(%args)
Construct a new CT::YAMLCacheDir object. See CT::Dir for other arguments. Note that content_as_yaml is always 1 as all files must be YAML files.
set($path, $val)
Not supported at the moment.
unset($path)
Not supported at the moment.
save()
Not supported at the moment.
SEE ALSO
Data::PrefixMerge, Config::Tree::Dir
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.