summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2019-08-27 12:24:29 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2019-08-27 12:24:29 (GMT)
commit745a02db1c53ed90e89bb9c6f57db450d2011106 (patch) (side-by-side diff)
tree659e1d828417cc08ada30a12e8d1bfd3d4a2a3a4
parent058e552bd37c0acf9d3a10fc743ac4d76d579b45 (diff)
downloadconfig-ast-745a02db1c53ed90e89bb9c6f57db450d2011106.tar.gz
config-ast-745a02db1c53ed90e89bb9c6f57db450d2011106.tar.bz2
Improve commit / lint API
* lib/Config/AST.pm (commit): Take optional keyword arguments. (lint): The argument (reference to a lexicon) is optional.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/Config/AST.pm60
1 files changed, 44 insertions, 16 deletions
diff --git a/lib/Config/AST.pm b/lib/Config/AST.pm
index 837bbac..fb10569 100644
--- a/lib/Config/AST.pm
+++ b/lib/Config/AST.pm
@@ -381,7 +381,23 @@ sub parse {
-=head2 $cfg->commit
+=head2 $cfg->commit([%hash])
Must be called after B<parse> to finalize the parse tree. This function
-does the actual syntax checking and applied default values to the statements
-where such are defined. Returns true on success.
+applies default values on settings where such are defined.
+
+Optional arguments control what steps are performed.
+
+=over 4
+
+=item lint => 1
+
+Forse syntax checking. This can be necessary if new nodes were added to
+the tree after parsing.
+
+=item lexicon => I<$hashref>
+
+Override the lexicon used for syntax checking and default value processing.
+
+=back
+
+Returns true on success.
@@ -390,6 +406,10 @@ where such are defined. Returns true on success.
sub commit {
- my ($self) = @_;
- # FIXME
- $self->fixup_tree($self->tree, $self->{_lexicon})
- if exists $self->{_lexicon};
+ my ($self, %opts) = @_;
+ my $lint = delete $opts{lint};
+ my $lexicon = delete $opts{lexicon} // $self->lexicon;
+ croak "unrecognized arguments" if keys(%opts);
+ if ($lexicon) {
+ $self->lint_subtree($lexicon, $self->tree) if $lint;
+ $self->fixup_tree($self->tree, $lexicon);
+ }
return $self->{_error_count} == 0;
@@ -767,3 +787,7 @@ names are separated by dots. I.e., the following two calls are equivalent:
$cfg->add_node('core.pidfile', $node)
-
+
+If the node already exists at B<$path>, new node is merged to it according
+to the lexical rules. I.e., for scalar value, new node overwrites the old
+one. For lists, it is appended to the list.
+
=cut
@@ -893,2 +917,6 @@ indicated by $path.
+If the setting already exists at B<$path>, the new value is merged to it
+according to the lexical rules. I.e., for scalars, B<$value> overwrites
+prior setting. For lists, it is appended to the list.
+
=cut
@@ -898,3 +926,3 @@ sub add_value {
$self->add_node($path, new Config::AST::Node::Value(value => $value,
- locus => $locus));
+ locus => $locus));
}
@@ -905,2 +933,5 @@ Sets the configuration variable B<@path> to B<$value>.
+No syntax checking is performed. To enforce syntax checking use
+B<add_value>.
+
=cut
@@ -1171,5 +1202,6 @@ sub lint_subtree {
-=head2 $cfg->lint(\%lex)
+=head2 $cfg->lint([\%lex])
-Checks the syntax according to the keyword lexicon B<%lex>. On success,
+Checks the syntax according to the keyword lexicon B<%lex> (or
+B<$cfg-E<gt>lexicon>, if called without arguments). On success,
applies eventual default values and returns true. On errors, reports
@@ -1185,7 +1217,3 @@ sub lint {
my ($self, $lexicon) = @_;
-
-# $synt->{'*'} = { section => { '*' => 1 }} ;
- $self->lint_subtree($lexicon, $self->tree);
- $self->fixup_tree($self->tree, $lexicon);
- return $self->{_error_count} == 0;
+ return $self->commit(lint => 1, lexicon => $lexicon);
}

Return to:

Send suggestions and report system problems to the System administrator.