diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-04 13:15:28 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-03-04 13:16:08 +0200 |
commit | 7f86dfc65aae2470dfdfbe4bef2a92161c35f193 (patch) | |
tree | 4c414e8ebb1971da2e46ec357115510980d8af65 /lib/App/Beam/Config.pm | |
parent | 14c6474d73fae6aeaa77dd19e10cf5615448aefb (diff) | |
download | beam-7f86dfc65aae2470dfdfbe4bef2a92161c35f193.tar.gz beam-7f86dfc65aae2470dfdfbe4bef2a92161c35f193.tar.bz2 |
Always keep locus with each statement; phase out the locations keyword.
Diffstat (limited to 'lib/App/Beam/Config.pm')
-rw-r--r-- | lib/App/Beam/Config.pm | 78 |
1 files changed, 44 insertions, 34 deletions
diff --git a/lib/App/Beam/Config.pm b/lib/App/Beam/Config.pm index 47a846e..d3ff4f7 100644 --- a/lib/App/Beam/Config.pm +++ b/lib/App/Beam/Config.pm @@ -69,12 +69,6 @@ Sets debug verbosity level. If B<1>, enables case-insensitive keyword matching. Default is B<0>, i.e. the keywords are case-sensitive. -=item B<locations> => B<0> | B<1> - -Controls the I<locations> mode. When locations mode is enabled. the -resulting object will store, along with each configuration setting, the -location in the source file where it was set. - =item B<parameters> => \%hash Defines the syntax table. See below for a description of B<%hash>. @@ -193,10 +187,6 @@ sub new { $self->{ci} = $v; } - if (defined($v = delete $_{locations})) { - $self->{locations} = $v; - } - if (defined($v = delete $_{parameters})) { if (ref($v) eq 'HASH') { $self->{parameters} = $v; @@ -423,11 +413,9 @@ sub readconfig { locus => new App::Beam::Config::Locus($file, $line)); $self->{error_count}++; } - if ($self->{locations}) { - $section->{-locus} = + $section->{-locus} = new App::Beam::Config::Locus($file, $line) unless exists $section->{-locus}; - } $section->{-order} = $self->{order}++; } } elsif (/([\w_-]+)\s*=\s*(.*)/) { @@ -495,14 +483,12 @@ sub readconfig { } } } - if ($self->{locations}) { - $section->{-locus}->add($file, $line); - unless (exists($section->{$k})) { - $section->{$k}{-locus} = - new App::Beam::Config::Locus(); - } - $section->{$k}{-locus}->add($file, $line); + + $section->{-locus}->add($file, $line); + unless (exists($section->{$k})) { + $section->{$k}{-locus} = new App::Beam::Config::Locus(); } + $section->{$k}{-locus}->add($file, $line); $section->{$k}{-order} = $self->{order}++; $section->{$k}{-value} = $v; } else { @@ -919,9 +905,16 @@ sub flatten { if (ref($sort) eq 'CODE') { $sort = sub { sort $sort @_ }; } elsif ($sort == SORT_PATH) { - $sort = sub { sort { join('.',@{$a->[0]}) cmp join('.', @{$b->[0]}) } @_ }; + $sort = sub { + sort { + join('.',@{$a->[0]}) cmp join('.', @{$b->[0]}) + } @_ + }; } elsif ($sort == SORT_NATURAL) { - $sort = sub { sort { $a->[1]{-order} <=> $b->[1]{-order} } @_ }; + $sort = sub { + sort { + $a->[1]{-order} <=> $b->[1]{-order} } @_ + }; } elsif ($sort == NO_SORT) { $sort = sub { @_ }; } else { @@ -962,14 +955,9 @@ sub lint { my $sref = $synt; my @domain; for (my $i = 0; $i <= $#{$dump->[0]}; $i++) { - my $k = $dump->[0][$i]; - $k = lc($k) if $self->{ci}; - if (exists($sref->{$k})) { - push @domain, $k; - $sref = $sref->{$k}; - } elsif (exists($sref->{'*'})) { - push @domain, $k; - $sref = $sref->{'*'}; + $sref = $self->descend_synt($sref, $dump->[0][$i]); + if (defined($sref)) { + push @domain, $dump->[0][$i]; } else { if (@domain) { my %opts; @@ -980,17 +968,22 @@ sub lint { $self->{error_count}++; @skip = @domain; } else { - $self->error("keyword \"$k\" is unknown", %opts); + $self->error("keyword \"$dump->[0][$i]\" is unknown", + %opts); $self->{error_count}++; } } next outer; } - if (ref($sref) ne 'HASH') { - $sref = {}; - } elsif (exists($sref->{section})) { + if (exists($sref->{select}) && !&{$sref->{select}}(@$dump)) { + next outer; + } + + if (exists($sref->{section})) { $sref = $sref->{section}; + } elsif ($i < $#{$dump->[0]}) { + next outer; } } @@ -1051,3 +1044,20 @@ sub lint { $self->fixup($synt); return !$self->{error_count}; } + +sub descend_synt { + my ($self, $sref, $k) = @_; + $k = lc($k) if $self->{ci}; + + if (exists($sref->{$k})) { + $sref = $sref->{$k}; + } elsif (exists($sref->{'*'})) { + $sref = $sref->{'*'}; + } else { + return undef; + } + + return {} unless ref($sref) eq 'HASH'; + + return $sref; +} |