summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2017-03-15 09:06:48 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2017-03-15 09:06:48 (GMT)
commiteeaf62bad36f0f46becb1fd92bb0112c1311dc8c (patch) (side-by-side diff)
tree9710f46aea830a90b6cac2aaf7b68a38b67d5aec
parent1c146d2aab40a87b241592eb894e0177a188eec9 (diff)
downloadbeam-perl.tar.gz
beam-perl.tar.bz2
Minor changesperl
* lib/App/Beam/Config.pm (check_mandatory): Remove (fixup): Rewrite to implement mandatory variable checking.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--lib/App/Beam/Config.pm108
1 files changed, 47 insertions, 61 deletions
diff --git a/lib/App/Beam/Config.pm b/lib/App/Beam/Config.pm
index d76cd1f..a50d920 100644
--- a/lib/App/Beam/Config.pm
+++ b/lib/App/Beam/Config.pm
@@ -372,54 +372,6 @@ sub parse_section {
return ($ref, $kw);
}
-sub check_mandatory {
- my $self = shift;
- my $kw = shift;
- my $section = shift;
- my $loc = shift;
-
- my $err = 0;
- while (my ($k, $d) = each %{$kw}) {
- if (ref($d) eq 'HASH') {
- if ($d->{mandatory} && !exists($section->{$k})) {
- $loc = $section->{-locus} if exists($section->{-locus});
- $self->error(exists($d->{section})
- ? "mandatory section ["
- . join(' ', @_, $k)
- . "] not present"
- : "mandatory variable \""
- . join('.', @_, $k)
- . "\" not set",
- locus => $loc);
- $self->{error_count}++;
- }
- if (exists($d->{section})) {
- if ($k eq '*') {
- while (my ($name, $vref) = each %{$section}) {
- next if $name =~ /^-/;
- if (exists($d->{select})
- && !&{$d->{select}}($vref, @_, $name)) {
- next;
- } elsif (is_section_ref($vref)) {
- $self->check_mandatory($d->{section},
- $vref,
- $loc,
- @_, $name);
- }
- }
- } elsif (exists($section->{$k})
- && (!exists($d->{select})
- || &{$d->{select}}($section->{$k}, @_, $k))) {
- $self->check_mandatory($d->{section},
- $section->{$k},
- $loc,
- @_, $k);
- }
- }
- }
- }
-}
-
sub readconfig {
my $self = shift;
my $file = shift;
@@ -553,14 +505,49 @@ sub readconfig {
}
sub fixup {
- my $self = shift;
- my $params = shift;
- while (my ($kv, $descr) = each %$params) {
- next unless ref($descr) eq 'HASH';
- if (exists($descr->{section})) {
- $self->fixup($descr->{section}, @_, $kv);
- } elsif (exists($descr->{default}) && !$self->isset(@_, $kv)) {
- $self->set(@_, $kv, $descr->{default});
+ my ($self, $section, $params, @path) = @_;
+
+ while (my ($k, $d) = each %{$params}) {
+ next unless ref($d) eq 'HASH';
+
+ if (exists($d->{default}) && !exists($section->{$k})) {
+ $section->{$k}{-locus} = new App::Beam::Config::Locus();
+ if (exists($d->{section})) {
+ $section->{$k} = $d->{default};
+ } else {
+ $section->{$k}{-value} = $d->{default};
+ }
+ }
+
+ if ($d->{mandatory} && !exists($section->{$k})) {
+ my $loc = $section->{-locus} if exists($section->{-locus});
+ $self->error(exists($d->{section})
+ ? "mandatory section ["
+ . join(' ', @path, $k)
+ . "] not present"
+ : "mandatory variable \""
+ . join('.', @path, $k)
+ . "\" not set",
+ locus => $loc);
+ $self->{error_count}++;
+ }
+
+ if (exists($d->{section})) {
+ if ($k eq '*') {
+ while (my ($name, $vref) = each %{$section}) {
+ next if $name =~ /^-/;
+ if (exists($d->{select})
+ && !&{$d->{select}}($vref, @path, $name)) {
+ next;
+ } elsif (is_section_ref($vref)) {
+ $self->fixup($vref, $d->{section}, @path, $name);
+ }
+ }
+ } elsif (exists($section->{$k})
+ && (!exists($d->{select})
+ || &{$d->{select}}($section->{$k}, @path, $k))) {
+ $self->fixup($section->{$k}, $d->{section}, @path, $k);
+ }
}
}
}
@@ -605,12 +592,11 @@ sub parse {
$self->debug(1, "parsing $self->{filename}");
$self->readconfig($self->{filename}, \%conf);
- $self->check_mandatory($self->{parameters}, \%conf);
+ $self->fixup(\%conf, $self->{parameters}) if exists $self->{parameters};
if ($self->{error_count} == 0) {
$self->{conf} = \%conf ;
$self->{updated} = 1;
- $self->fixup($self->{parameters}) if exists $self->{parameters};
return 1;
}
return 0;
@@ -1082,9 +1068,9 @@ sub lint {
# $synt->{'*'} = { section => { '*' => 1 }} ;
$self->_lint($synt, $self->{conf});
- $self->check_mandatory($synt, $self->{conf});
- return 0 if $self->{error_count};
- $self->fixup($synt);
+ if ($self->{error_count} == 0) {
+ $self->fixup($self->{conf}, $synt);
+ }
return $self->{error_count} == 0;
}

Return to:

Send suggestions and report system problems to the System administrator.