Config::Tree::Dir - Read configuration tree from a directory


Config-Tree documentation  | view source Contained in the Config-Tree distribution.

Index


NAME

Top

Config::Tree::Dir - Read configuration tree from a directory

SYNOPSIS

Top

 # 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

DESCRIPTION

Top

ATTRIBUTES

Top

METHODS

Top

new(%args)

Construct a new Config::Tree::Dir object. Arguments.

file_is_excluded

get_tree_for

set($path, $val)

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($path)

Unset config variable.

save()

Does nothing. All changes are immediately written by set() or unset().

SEE ALSO

Top

Data::Schema, Config::Tree::Base

AUTHOR

Top

Steven Haryanto, <stevenharyanto at gmail.com>

COPYRIGHT & LICENSE

Top


Config-Tree documentation  | view source Contained in the Config-Tree distribution.