summaryrefslogtreecommitdiff
path: root/lib/Apache/Config/Preproc/include.pm
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2017-12-07 05:37:40 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2017-12-07 05:37:40 +0200
commit7a06349587e2fe0cb1b5c74185d2f507173409c4 (patch)
treefb488c11d0b6185defa43cc717ab0c37356fb538 /lib/Apache/Config/Preproc/include.pm
parentb4cf13ffdacb47686cdee6b31155f325800c9bcc (diff)
downloadacpp-7a06349587e2fe0cb1b5c74185d2f507173409c4.tar.gz
acpp-7a06349587e2fe0cb1b5c74185d2f507173409c4.tar.bz2
Rename module to Apache::Config::Preproc
Diffstat (limited to 'lib/Apache/Config/Preproc/include.pm')
-rw-r--r--lib/Apache/Config/Preproc/include.pm54
1 files changed, 54 insertions, 0 deletions
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;

Return to:

Send suggestions and report system problems to the System administrator.