diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-07 05:37:40 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2017-12-07 05:37:40 +0200 |
commit | 7a06349587e2fe0cb1b5c74185d2f507173409c4 (patch) | |
tree | fb488c11d0b6185defa43cc717ab0c37356fb538 /lib/Apache/Config/Preproc | |
parent | b4cf13ffdacb47686cdee6b31155f325800c9bcc (diff) | |
download | acpp-7a06349587e2fe0cb1b5c74185d2f507173409c4.tar.gz acpp-7a06349587e2fe0cb1b5c74185d2f507173409c4.tar.bz2 |
Rename module to Apache::Config::Preproc
Diffstat (limited to 'lib/Apache/Config/Preproc')
-rw-r--r-- | lib/Apache/Config/Preproc/compact.pm | 17 | ||||
-rw-r--r-- | lib/Apache/Config/Preproc/ifmodule.pm | 34 | ||||
-rw-r--r-- | lib/Apache/Config/Preproc/include.pm | 54 |
3 files changed, 105 insertions, 0 deletions
diff --git a/lib/Apache/Config/Preproc/compact.pm b/lib/Apache/Config/Preproc/compact.pm new file mode 100644 index 0000000..f28d848 --- /dev/null +++ b/lib/Apache/Config/Preproc/compact.pm @@ -0,0 +1,17 @@ +package Apache::Config::Preproc::compact; +use strict; +use warnings; + +sub new { + bless {}, shift +} + +sub expand { + my ($self, $tree, $d, $repl) = @_; + return $d->type eq 'blank' || $d->type eq 'comment'; +} + +1; + + + diff --git a/lib/Apache/Config/Preproc/ifmodule.pm b/lib/Apache/Config/Preproc/ifmodule.pm new file mode 100644 index 0000000..9fe73b7 --- /dev/null +++ b/lib/Apache/Config/Preproc/ifmodule.pm @@ -0,0 +1,34 @@ +package Apache::Config::Preproc::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; + diff --git a/lib/Apache/Config/Preproc/include.pm b/lib/Apache/Config/Preproc/include.pm new file mode 100644 index 0000000..800e77a --- /dev/null +++ b/lib/Apache/Config/Preproc/include.pm @@ -0,0 +1,54 @@ +package Apache::Config::Preproc::include; +use strict; +use warnings; +use Apache::Admin::Config; +use Apache::Config::Preproc; +use File::Spec; +use Carp; + +sub new { + bless { included => {} }, shift +} + +sub expand { + my ($self, $tree, $d, $repl) = @_; + + if ($d->type eq 'directive' && $d->name =~ /^include(optional)?$/i) { + my $optional = $1; + + my $pat = $tree->dequote($d->value); + unless (File::Spec->file_name_is_absolute($pat)) { + if (my $d = $tree->server_root) { + $pat = File::Spec->catfile($d, $pat); + } + } + + my @filelist = glob $pat; + if (@filelist) { + foreach my $file (@filelist) { + if ($self->check_included($file)) { + croak "file $file already included"; + } + if (my $inc = new Apache::Admin::Config($file, + @{$tree->options})) { + push @$repl, $inc->select; + } else { + croak $Apache::Admin::Config::ERROR; + } + } + } + return 1; + } + + return 0; +} + +sub check_included { + my ($self, $file) = @_; + my ($dev,$ino) = stat($file) or return 0; + return 1 if $self->{included}{$dev}{$ino}; + $self->{included}{$dev}{$ino} = 1; + return 0; +} + +1; |