| Config-Tree documentation | view source | Contained in the Config-Tree distribution. |
Config::Tree::File - Read configuration tree from a YAML file
# in config.yaml:
foo:
bar: 2
baz: 3
# in script.pl:
use Config::Tree::File;
my $conf = Config::Tree::File->new(
path => '/path/to/config.yaml',
# watch => 10, # currently not implemented
# schema => ...,
# when_invalid => ...,
# include_path_re => qr/.../,
# exclude_path_re => qr/.../,
ro => 0,
);
my $val = $conf->get('/foo/bar'); # 2
$conf->cd('/foo');
$conf->set('bar', 10); # same as set('/foo/bar', 10);
$conf->save(); # writes back to file
Construct a new Config::Tree::File object. Arguments.
path. Required. Path to YAML file. ro. Optional, default is 0. Whether we should disallow set() and save(). 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 over exclude_path_re. schema. Optional. When specified, after the tree is retrieved from file, it
will be validated against this schema using Data::Schema. must_exist. Optional, default 0. If set to 1, then the file/dir must exist
and an error is thrown if it doesn't.Set config variable.
Will not write to file until save() is called.
Save config variable to file.
If schema is specified, config tree will be validated first and an error will be thrown if the config does not validate.
Steven Haryanto, <stevenharyanto at gmail.com>
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.
| Config-Tree documentation | view source | Contained in the Config-Tree distribution. |