Apache-Config-Preproc
view release on metacpan or search on metacpan
lib/Apache/Config/Preproc/ifdefine.pm view on Meta::CPAN
package Apache::Config::Preproc::ifdefine;
use parent 'Apache::Config::Preproc::Expand';
use strict;
use warnings;
use Carp;
our $VERSION = '1.03';
sub new {
my ($class, $conf) = @_;
my $self = $class->SUPER::new($conf);
@{$self->{D}}{@_} = (1) x @_;
return $self;
}
sub find_define {
my ($self,$elt,$id) = @_;
while (my $p = $elt->parent) {
if (grep {
(split /\s+/, $_->value)[0] eq $id
} $p->directive('define')) {
return 1;
}
}
return;
}
sub _changed_in_section {
my ($self, $section, $id, $before) = @_;
foreach my $d (reverse $section->select) {
if ($before) {
if ($d == $before) {
$before = undef;
}
next;
}
if ($d->type eq 'directive') {
if ($d->name =~ m/^(un)?define$/i && $d->value eq $id) {
if ($1) {
$self->undefine($id);
} else {
$self->define($id);
}
return 1;
}
} elsif ($d->type eq 'section' && lc($d->name) eq 'virtualhost') {
# Need to descend into VirtualHost, because accorind to the
# Apache docs
# see (https://httpd.apache.org/docs/2.4/mod/core.html#define):
#
# While [the Define] directive is supported in virtual host
# context, the changes it makes are visible to any later
# configuration directives, beyond any enclosing virtual host.
#
# The same is said about the UnDefine directive.
return 1 if $self->_changed_in_section($d, $id);
}
}
return 0;
}
sub is_defined {
my ($self,$id,$d) = @_;
unless ($self->{D}{$id}) {
my $before = $d;
while ($d = $d->parent) {
last if $self->_changed_in_section($d, $id, $before);
( run in 0.747 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )