| Config-Tree documentation | view source | Contained in the Config-Tree distribution. |
Config::Tree::Dir - Read configuration tree from a directory
# in confdir/
# foo/
# bar # content: '3'
# baz # content: "hello, world!\n\n"
# binary # content: "\xff\xfe\n"
# quux # content: '{i: 1, j: 2}'
# flag # 0 bytes
# in script.pl:
use Config::Tree::Dir;
my $conf = Config::Tree::Dir->new(
path => '/path/to/confdir',
#watch => 10, # currently not implemented
#allow_symlink => 0,
#check_owner => 1,
#content_as_yaml => 0,
#include_path_re => qr/.../,
#exclude_path_re => qr/.../,
#include_file_re => qr/.../,
#exclude_file_re => qr/.../,
#tie_cache_opts => {...} # currently not implemented
ro => 0,
);
# when content_as_yaml is 0:
$conf->get('/foo/bar'); # 3
$conf->get('/foo/baz'); # "hello, world!", newlines stripped
$conf->get('/foo/binary'); # "\xff\xfe\n", newlines not stripped in binaries
$conf->get('/foo/flag'); # 1, all zero byte files is assumed to mean True
# when content_as_yaml is 1:
$conf->get('/foo/bar'); # 3
$conf->get('/foo/baz'); # "hello, world!", YAML parser also strips newlines
$conf->get('/foo/flag'); # undef
$conf->cd('/foo');
$conf->set('bar', 10); # same as set('/foo/bar', 10);
$conf->save(); # writes back to directory
Construct a new Config::Tree::Dir object. Arguments.
path. Required. Path to config directory. ro. Optional, default is 0. Whether we should disallow set() and save(). allow_symlink. Default is 1 (only allow if owner matches). See
Config::Tree::BaseFS for more information. allow_different_owner. Optional, default is 0 (don't allow files/dirs with
different owner as the running user). See Config::Tree::BaseFS for more
information. 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. exclude_file_re. Optional. Default is qr/\A#|~\z/ (backup files). When set, files
with name matching the regex will not be read. See also: include_file_re. include_file_re. Optional. When set, only files with name matching the regex
will be read. Takes precedence over exclude_file_re. content_as_yaml. Optional, default is 0. When set to 1, all files are assumed
to be YAML documents and will be parsed. Otherwise, these conventions are used
when retrieving file contents:
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 immediately create necessary subdirectories and write to file.
Example: set("/a/b/c", 1) will create a/ and a/b/ subdirectories, and file a/b/c containing "1". If a already exists as a file, it will be removed
When $val is a reference and content_as_yaml is 1, a YAML dump will be written to the file.
Unset config variable.
Does nothing. All changes are immediately written by set() or unset().
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. |