summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
@@ -379,19 +379,39 @@ sub parse {
379 croak "call to abstract method" 379 croak "call to abstract method"
380} 380}
381 381
382=head2 $cfg->commit 382=head2 $cfg->commit([%hash])
383 383
384Must be called after B<parse> to finalize the parse tree. This function 384Must be called after B<parse> to finalize the parse tree. This function
385does the actual syntax checking and applied default values to the statements 385applies default values on settings where such are defined.
386where such are defined. Returns true on success. 386
387Optional arguments control what steps are performed.
388
389=over 4
390
391=item lint => 1
392
393Forse syntax checking. This can be necessary if new nodes were added to
394the tree after parsing.
395
396=item lexicon => I<$hashref>
397
398Override the lexicon used for syntax checking and default value processing.
399
400=back
401
402Returns true on success.
387 403
388=cut 404=cut
389 405
390sub commit { 406sub commit {
391 my ($self) = @_; 407 my ($self, %opts) = @_;
392 # FIXME 408 my $lint = delete $opts{lint};
393 $self->fixup_tree($self->tree, $self->{_lexicon}) 409 my $lexicon = delete $opts{lexicon} // $self->lexicon;
394 if exists $self->{_lexicon}; 410 croak "unrecognized arguments" if keys(%opts);
411 if ($lexicon) {
412 $self->lint_subtree($lexicon, $self->tree) if $lint;
413 $self->fixup_tree($self->tree, $lexicon);
414 }
395 return $self->{_error_count} == 0; 415 return $self->{_error_count} == 0;
396} 416}
397 417
@@ -765,7 +785,11 @@ names are separated by dots. I.e., the following two calls are equivalent:
765 $cfg->add_node(qw(core pidfile), $node) 785 $cfg->add_node(qw(core pidfile), $node)
766 786
767 $cfg->add_node('core.pidfile', $node) 787 $cfg->add_node('core.pidfile', $node)
768 788
789If the node already exists at B<$path>, new node is merged to it according
790to the lexical rules. I.e., for scalar value, new node overwrites the old
791one. For lists, it is appended to the list.
792
769=cut 793=cut
770 794
771sub add_node { 795sub add_node {
@@ -891,18 +915,25 @@ sub add_node {
891Adds a statement node with the given B<$value> and B<$locus> in position, 915Adds a statement node with the given B<$value> and B<$locus> in position,
892indicated by $path. 916indicated by $path.
893 917
918If the setting already exists at B<$path>, the new value is merged to it
919according to the lexical rules. I.e., for scalars, B<$value> overwrites
920prior setting. For lists, it is appended to the list.
921
894=cut 922=cut
895 923
896sub add_value { 924sub add_value {
897 my ($self, $path, $value, $locus) = @_; 925 my ($self, $path, $value, $locus) = @_;
898 $self->add_node($path, new Config::AST::Node::Value(value => $value, 926 $self->add_node($path, new Config::AST::Node::Value(value => $value,
899 locus => $locus)); 927 locus => $locus));
900} 928}
901 929
902=head2 $cfg->set(@path, $value) 930=head2 $cfg->set(@path, $value)
903 931
904Sets the configuration variable B<@path> to B<$value>. 932Sets the configuration variable B<@path> to B<$value>.
905 933
934No syntax checking is performed. To enforce syntax checking use
935B<add_value>.
936
906=cut 937=cut
907 938
908sub set { 939sub set {
@@ -1169,9 +1200,10 @@ sub lint_subtree {
1169 } 1200 }
1170} 1201}
1171 1202
1172=head2 $cfg->lint(\%lex) 1203=head2 $cfg->lint([\%lex])
1173 1204
1174Checks the syntax according to the keyword lexicon B<%lex>. On success, 1205Checks the syntax according to the keyword lexicon B<%lex> (or
1206B<$cfg-E<gt>lexicon>, if called without arguments). On success,
1175applies eventual default values and returns true. On errors, reports 1207applies eventual default values and returns true. On errors, reports
1176them using B<error> and returns false. 1208them using B<error> and returns false.
1177 1209
@@ -1183,11 +1215,7 @@ after calling B<parse>.
1183 1215
1184sub lint { 1216sub lint {
1185 my ($self, $lexicon) = @_; 1217 my ($self, $lexicon) = @_;
1186 1218 return $self->commit(lint => 1, lexicon => $lexicon);
1187# $synt->{'*'} = { section => { '*' => 1 }} ;
1188 $self->lint_subtree($lexicon, $self->tree);
1189 $self->fixup_tree($self->tree, $lexicon);
1190 return $self->{_error_count} == 0;
1191} 1219}
1192 1220
1193=head1 SEE ALSO 1221=head1 SEE ALSO

Return to:

Send suggestions and report system problems to the System administrator.