diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-04 18:05:51 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-04 18:05:51 +0200 |
commit | 9dbc51556ad400f03495b3b85b0b5995362cd35c (patch) | |
tree | 20416ffc86e3a3c5d0614a37cebe629bc30479cc /lib/App | |
parent | bf855bb78bb759d1f733cdb21032e5fbfa403572 (diff) | |
download | beam-9dbc51556ad400f03495b3b85b0b5995362cd35c.tar.gz beam-9dbc51556ad400f03495b3b85b0b5995362cd35c.tar.bz2 |
Improve config syntax verification.
Fix processing of the '*' entry in the syntax hashes.
The entry '*' => '*' in the syntax hash declares that any settings
and any subsections are also allowed.
Diffstat (limited to 'lib/App')
-rw-r--r-- | lib/App/Beam/Config.pm | 64 |
1 files changed, 54 insertions, 10 deletions
diff --git a/lib/App/Beam/Config.pm b/lib/App/Beam/Config.pm index 32c1a32..829e6e3 100644 --- a/lib/App/Beam/Config.pm +++ b/lib/App/Beam/Config.pm @@ -126,6 +126,16 @@ of the statement appends its value to the end of the array. Defines a regular expression to which must be matched by the value of the setting, otherwise a syntax error will be reported. +=item select => I<coderef> + +Points to a function to be called to decide whether to apply this hash to +a particular configuration setting. The function is called as + + &{$coderef}($vref, @path) + +where $vref is a reference to the setting (use $vref->{-value}, to obtain +the actual value), and @path is its patname. + =item check => I<coderef> Defines a code which will be called after parsing the statement in order to @@ -168,7 +178,28 @@ and is allowed to have any other settings as well. '*' => 1 } } - + +Everything said above applies to the B<'*'> as well. E.g. the following +example declares the B<[code]> section, which must have the B<pidfile> +setting and is allowed to have I<subsections> with arbitrary settings. + + code => { + section => { + pidfile = { mandatory => 1 }, + '*' => { + section => { + '*' => 1 + } + } + } + } + +The special entry + + '*' => '*' + +means "any settings and any subsections". + =cut sub new { @@ -313,9 +344,26 @@ sub parse_section { } unless ref($ref->{$name}) eq 'HASH'; $ref = $ref->{$name}; - if (defined($kw) - and ref($kw) eq 'HASH' and exists($kw->{$name}{section})) { - $kw = $kw->{$name}{section}; + if (defined($kw) and ref($kw) eq 'HASH') { + my $synt; + if (exists($kw->{$name})) { + $synt = $kw->{$name}; + } elsif (exists($kw->{'*'})) { + $synt = $kw->{'*'}; + if ($synt eq '*') { + $name = undef; + next; + } + } + if (defined($synt) + && ref($synt) eq 'HASH' + && exists($synt->{section})) { + $kw = $synt->{section}; + } else { + $kw = undef; + } + } else { + $kw = undef; } $name = undef; @@ -416,13 +464,9 @@ sub readconfig { new App::Beam::Config::Locus($file, $line)); if (exists($self->{parameters}) and !defined($kw)) { $self->error("unknown section", - locus => new App::Beam::Config::Locus($file, $line)); + locus => $section->{-locus}); $self->{error_count}++; } - $section->{-locus} = - new App::Beam::Config::Locus($file, $line) - unless exists $section->{-locus}; - $section->{-order} = $self->{order}++; } } elsif (/([\w_-]+)\s*=\s*(.*)/) { my ($k, $v) = ($1, $2); @@ -1037,6 +1081,6 @@ sub lint { $self->check_mandatory($synt, $self->{conf}); return 0 if $self->{error_count}; $self->fixup($synt); - return !$self->{error_count}; + return $self->{error_count} == 0; } |