| Config-Tree documentation | Contained in the Config-Tree distribution. |
Config::Tree::Var - Read configuration tree from Perl data structure
use Config::Tree::Var;
my $tree = {
foo => {
bar => 2,
baz => 3,
}
};
my $conf = Config::Tree::Var->new(
tree => $var,
# 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);
Construct a new Config::Tree::Var object. Arguments.
tree. Required. Perl data structure that contains the tree. Must be a
hashref. ro. Optional, default is 0. Whether we should disallow set() and save(). when_invalid. Optional, default is 'die'. What to do when file content does
not validate with supplied schema. Choices: 'die', 'warn', 'quiet'. 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, it will be
validated against this schema using Data::Schema.Set config variable in the tree.
Does nothing. set() will already modify the Perl data structure.
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 | Contained in the Config-Tree distribution. |
package Config::Tree::Var;
use Moose; extends 'Config::Tree::Base';
has _loaded => (is => 'rw', default => 0); has _mtime => (is => 'rw', default => 0); has tree => (is => 'rw', default => 0);
sub BUILD { my ($self) = @_; die "tree must be specified" unless defined($self->tree); $self->name("var") unless $self->name; } sub _get_tree { my ($self) = @_; unless ($self->_loaded) { die "tree must be hashref" unless ref($self->tree) eq 'HASH'; $self->_loaded(1); $self->_mtime(time); } ($self->tree, $self->_mtime); } sub _format_validation_error { my ($self, $res) = @_; sprintf("%sconfig has %d error(s): `%s`", ($self->modified ? "modified " : ""), scalar(@{ $res->{errors} }), join(", ", @{ $res->{errors} })); }
sub _save { my ($self) = @_; 1; }
__PACKAGE__->meta->make_immutable; 1;