aboutsummaryrefslogtreecommitdiff
path: root/lib/Apache/Inject.pm
blob: a9f1a618cd635ce49b5d27821b645e6b3dc6dc8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package Apache::Inject;

use strict;
use warnings;

use Apache2::CmdParms ();
use Apache2::Module ();
use Apache2::Const qw/OR_LIMIT OR_AUTHCFG TAKE12/;

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) = @_;

	# Validate arguments and construct corresponding directives
	my @vars;
	my @names = qw/InjectHead InjectFoot/;
	for (@args) {
		die 'Arguments to Inject directive cannot contain quotes' if /"/;
		push @vars, 'PerlSetVar ' . (shift @names) . ' ' . $_;
	}

	# Add relevant directives to current configuration
	$parms->add_config(['SetHandler perl-script',
	                    'PerlResponseHandler Apache::Inject::Handler',
	                    @vars]);
}

1;
__END__

=head1 NAME

Apache::Inject - Apache directive for injecting HTML headers and footers

=head1 SYNOPSIS

DocumentRoot /uar/local/www/apache24/data
PerlModule Apache::Inject
<Directory /usr/local/www/apache24/data>
    Inject head.html foot.html
</Directory>

=head1 DESCRIPTION

Apache::Inject is a mod_perl module that adds the Inject directive.
It injects a header before the body and (optionally) a footer after the body
of any requested HTML file.

=cut