aboutsummaryrefslogtreecommitdiff
path: root/lib/Apache/Inject.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Apache/Inject.pm')
-rw-r--r--lib/Apache/Inject.pm76
1 files changed, 51 insertions, 25 deletions
diff --git a/lib/Apache/Inject.pm b/lib/Apache/Inject.pm
index 2c05b14..09bf18a 100644
--- a/lib/Apache/Inject.pm
+++ b/lib/Apache/Inject.pm
@@ -11,35 +11,31 @@ use Apache2::Const qw/OR_LIMIT OR_AUTHCFG TAKE12/;
use Apache2::Log ();
use Apache2::Module ();
-my @directives = (
- { name => 'Inject',
- func => __PACKAGE__.'::Inject',
- req_override => OR_LIMIT|OR_AUTHCFG,
- args_how => TAKE12,
- errmsg => 'Inject HeadFile[!] FootFile[!]' }
-);
+my @directives = ({
+ name => 'Inject',
+ func => __PACKAGE__.'::Inject',
+ req_override => OR_LIMIT|OR_AUTHCFG,
+ args_how => TAKE12,
+ errmsg => 'Inject HeadFile[!] FootFile[!]',
+});
Apache2::Module::add(__PACKAGE__, \@directives);
sub Inject {
my ($self, $parms, @args) = @_;
- for (@args) {
- if ($_ eq ' ') {
- $parms->server->log_error('Inject: Argument cannot be a single space');
- }
- }
-
# Construct directives for passing arguments to handler
my $head = $args[0];
- my $foot = $args[1] || ' '; # single space signifies absence of argument
+ my $foot = $args[1] || '-'; # single hyphen signifies absence of argument
$head =~ s/\\/\\\\/; s/"/\\"/;
$foot =~ s/\\/\\\\/; s/"/\\"/;
# Add relevant directives to current configuration
- $parms->add_config(['SetHandler perl-script',
- 'PerlResponseHandler Apache::Inject::Handler',
- qq{PerlSetVar InjectHead "$head"},
- qq{PerlSetVar InjectFoot "$foot"}]);
+ $parms->add_config([
+ 'SetHandler perl-script',
+ 'PerlResponseHandler Apache::Inject::Handler',
+ qq{PerlSetVar InjectHead "$head"},
+ qq{PerlSetVar InjectFoot "$foot"},
+ ]);
}
1;
@@ -54,11 +50,23 @@ Apache::Inject - Apache directive for injecting HTML headers and footers
LoadModule perl_module libexec/apache24/mod_perl.so
PerlLoadModule Apache::Inject
- DocumentRoot /uar/local/www/apache24/data
+ DocumentRoot /usr/local/www/apache24/data
+
<Directory /usr/local/www/apache24/data>
+ # Inject both header and footer on all pages on the server
Inject head.html foot.html
</Directory>
+ <Location /blog>
+ # Inject only header on pages under /blog
+ Inject head.html
+ </Location>
+
+ <Files index.html>
+ # Inject only footer on pages named index.html
+ Inject - foot.html
+ </Files>
+
=head1 DESCRIPTION
Apache::Inject is a mod_perl module that adds an Apache directive
@@ -129,6 +137,30 @@ an unprivileged user and will be skipped if they are run as root.
This is relevant if you install Apache::Inject via App::Cpan, which
normally runs as root.
+=head1 SYNTAX
+
+The Inject directive takes one or two arguments:
+
+ Inject HEADER_FILE [FOOTER_FILE]
+
+Each argument can consist of one of two things:
+
+=over
+
+=item 1.
+the path to a file relative to the document root, or
+
+=item 2.
+a single hyphen (C<->), signifying the absence of an argument.
+
+=back
+
+Passing a hyphen as the first argument disables the header, and
+passing a hyphen as the second argument disables the footer.
+
+If you leave out the second argument, then it is implicitly equivalent
+to a hyphen.
+
=head1 OPERATION
Behind the scenes, the Inject directive works as an alias for
@@ -160,12 +192,6 @@ Apache handle it as it would if the Inject directive were not used.
=over
-=item Error: Argument cannot be a single space
-
-In the current implementation, the file names given to Inject are
-not allowed to consist solely of a single space, as this is a special
-value signifying the absence of an argument.
-
=item Error: InjectHead/InjectFoot should not begin with slash, as
it is already always relative to document root