diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-06 22:06:42 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-06 22:06:42 +0200 |
commit | b4cf13ffdacb47686cdee6b31155f325800c9bcc (patch) | |
tree | 8e8d4ccc12f5a7702f1e7a8f09aceceb84990663 | |
parent | 7cb9b8ae0c32cedad537042b969d2762d3cafbac (diff) | |
download | acpp-b4cf13ffdacb47686cdee6b31155f325800c9bcc.tar.gz acpp-b4cf13ffdacb47686cdee6b31155f325800c9bcc.tar.bz2 |
Implement the "ifmodule" expansion
-rw-r--r-- | lib/Apache/Admin/Config/Expand/ifmodule.pm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Apache/Admin/Config/Expand/ifmodule.pm b/lib/Apache/Admin/Config/Expand/ifmodule.pm new file mode 100644 index 0000000..603f90d --- /dev/null +++ b/lib/Apache/Admin/Config/Expand/ifmodule.pm @@ -0,0 +1,34 @@ +package Apache::Admin::Config::Expand::ifmodule; +use strict; +use warnings; + +sub new { + bless {}, shift +} + +sub expand { + my ($self, $tree, $d, $repl) = @_; + if ($d->type eq 'section' && lc($d->name) eq 'ifmodule') { + my $id = $d->value; + my $negate = $id =~ s/^!//; + my $res = $self->module_loaded($tree, $id); + if ($negate) { + $res = !$res; + } + if ($res) { + push @$repl, $d->select; + } + return 1; + } + return 0; +} + +sub module_loaded { + my ($self, $tree, $id) = @_; + return grep { + (split /\s+/, $_->value)[0] eq $id + } $tree->directive('loadmodule'); +} + +1; + |