diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-09 09:45:57 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-09 09:48:37 +0200 |
commit | 55362f22aae333d26b9ea3fa65733ec1e57d53bc (patch) | |
tree | f194111fb1f4d778dd04384b7758c03567e1c58d /lib/Apache/Config/Preproc/macro.pm | |
parent | a5889328c8e16054d27e662d393555deaa78ef5c (diff) | |
download | acpp-55362f22aae333d26b9ea3fa65733ec1e57d53bc.tar.gz acpp-55362f22aae333d26b9ea3fa65733ec1e57d53bc.tar.bz2 |
macro processor: implement the 'keep' list
* lib/Apache/Config/Preproc/macro.pm: Implement the retention list. Macros
from this list are exempt from expansion.
* lib/Apache/Config/Preproc.pm: Document changes to the macro processor
* t/04macro02.t: New test case.
Diffstat (limited to 'lib/Apache/Config/Preproc/macro.pm')
-rw-r--r-- | lib/Apache/Config/Preproc/macro.pm | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/lib/Apache/Config/Preproc/macro.pm b/lib/Apache/Config/Preproc/macro.pm index ab97b62..c0538d0 100644 --- a/lib/Apache/Config/Preproc/macro.pm +++ b/lib/Apache/Config/Preproc/macro.pm @@ -5,8 +5,22 @@ use Text::ParseWords; use Carp; sub new { - croak "too many arguments" unless @_ == 2; - bless {}, shift + my $self = bless { keep => {} }, shift; + shift; # Skip the ref to tree root + croak "bad number of arguments: @_" if @_ % 2; + local %_ = @_; + my $v; + if ($v = delete $_{keep}) { + if (ref($v)) { + croak "keep argument must be a scalar or listref" + unless ref($v) eq 'ARRAY'; + } else { + $v = [$v]; + } + @{$self->{keep}}{@$v} = @$v; + } + croak "unrecognized arguments" if keys(%_); + return $self; } sub macro { @@ -16,14 +30,15 @@ sub macro { sub install_macro { my ($self, $defn) = @_; + return 0 if $self->{keep}{$defn->name}; $self->{macro}{$defn->name} = $defn; + return 1; } sub expand { my ($self, $d, $repl) = @_; if ($d->type eq 'section' && lc($d->name) eq 'macro') { - $self->install_macro(Apache::Config::Preproc::macro::defn->new($d)); - return 1; + return $self->install_macro(Apache::Config::Preproc::macro::defn->new($d)); } if ($d->type eq 'directive' && lc($d->name) eq 'use') { my ($name,@args) = parse_line(qr/\s+/, 0, $d->value); @@ -101,12 +116,30 @@ Apache::Config::Preproc::macro - expand macro statements $x = new Apache::Config::Preproc '/path/to/httpd.conf', -expand => [ qw(macro) ]; + $x = new Apache::Config::Preproc '/path/to/httpd.conf', + -expand => [ { macro => [ keep => $listref ] } ]; + =head1 DESCRIPTION Processes B<Macro> and B<Use> statements (see B<mod_macro>) in the Apache configuration parse tree. B<Macro> statements are removed. Each B<Use> statement is replaced by the -expansion of the macro named in its argument. +expansion of the macro named in its argument. + +The constructor accepts the following arguments: +=over 4 + +=item B<keep =E<gt>> I<$listref> + +List of macro names to exclude from expanding. Each B<E<lt>MacroE<gt>> and +B<Use> statement with a name from I<$listref> as its first argument will be +retained in the parse tree. + +As a syntactic sugar, I<$listref> can also be a scalar value. This is +convenient when a single macro name is to be retained. + +=back + =cut |