summaryrefslogtreecommitdiffabout
path: root/lib/Config/Tree.pm
Side-by-side diff
Diffstat (limited to 'lib/Config/Tree.pm') (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Config/Tree.pm43
1 files changed, 30 insertions, 13 deletions
diff --git a/lib/Config/Tree.pm b/lib/Config/Tree.pm
index 39e0de9..f22d8e5 100644
--- a/lib/Config/Tree.pm
+++ b/lib/Config/Tree.pm
@@ -507,20 +507,21 @@ sub _get_section_synt {
=cut
sub add_node {
- my ($self, $path, $v, $locus) = @_;
+ my ($self, $path, $node) = @_;
unless (ref($path) eq 'ARRAY') {
$path = [ split(/\./, $path) ]
}
my $kw = $self->{_parameters} // { '*' => '*' };
- my $node = $self->tree;
+ my $tree = $self->tree;
my $pn = $#{$path};
my $name;
+ my $locus = $node->locus;
for (my $i = 0; $i < $pn; $i++) {
$name = ${$path}[$i];
- unless ($node->is_section) {
+ unless ($tree->is_section) {
$self->error(join('.', @{$path}[0..$i]) . ": not a section");
$self->{_error_count}++;
return;
@@ -533,10 +534,10 @@ sub add_node {
return;
}
- if (my $subtree = $node->subtree($name)) {
- $node = $subtree;
+ if (my $subtree = $tree->subtree($name)) {
+ $tree = $subtree;
} else {
- $node = $node->subtree(
+ $tree = $tree->subtree(
$name => new Config::Tree::Node::Section(
order => $self->{_order}++,
locus => $locus->clone)
@@ -553,12 +554,24 @@ sub add_node {
return;
}
+ if ($node->is_section) {
+ if ($tree->has_key($name)) {
+ $tree->locus->add($locus);
+ $tree->subtree($name)->merge($node);
+ } else {
+ $tree->subtree($name => $node);
+ }
+ return $node;
+ }
+
+ my $v = $node->value;
+
if (ref($x) eq 'HASH') {
my $errstr;
my $prev_val;
- if ($node->has_key($name)) {
+ if ($tree->has_key($name)) {
# FIXME: is_value?
- $prev_val = $node->subtree($name)->value;
+ $prev_val = $tree->subtree($name)->value;
}
if (exists($x->{re})) {
if ($v !~ /$x->{re}/) {
@@ -585,21 +598,25 @@ sub add_node {
}
}
- $node->locus->add($locus->clone);
+ $tree->locus->add($locus->clone);
my $newnode;
- if ($newnode = $node->subtree($name)) {
+ if ($newnode = $tree->subtree($name)) {
$newnode->locus->add($locus);
} else {
- $newnode = $node->subtree(
- $name => new Config::Tree::Node::Value(locus => $locus)
- );
+ $newnode = $tree->subtree($name => $node);
}
$newnode->order($self->{order}++);
$newnode->value($v);
return $newnode;
}
+sub add_value {
+ my ($self, $path, $value, $locus) = @_;
+ $self->add_node($path, new Config::Tree::Node::Value(value => $value,
+ locus => $locus));
+}
+
sub commit {
my ($self) = @_;
# FIXME

Return to:

Send suggestions and report system problems to the System administrator.