Hello! All,
I am new user on mod_perl, and study it from the book, "Write Apache Modules with
Perl and C". I installed a Handler, Footer.pm, in apache by embeding the following
lines in the file apache.conf:
Alias / /usr/local/share/apache/htdocs/
<Location />
SetHandler perl-script
PerlHandler Apache::Footer
</Location>
It works but the scripts in /cgi-bin/ do not function at all! If I comment this
handler
, the cgi-bin works again. I don't know whay? Can somebody tell me the reason and how
to overcome this side effect? The code and the system information is appended with
this
email as follow.
Many Thanks!
Sam Xie
========================================================================================
Operating System: FreeBSD-4.0 Current
Perl Version: Perl 5.005_03
Apache Version: Apache13-php4
Mod_perl version: mod_perl-1.22
Perl Handler: Footer.pm
-----------------Code -----------------------------------------------------------------
package Apache::Footer;
use strict;
use Apache::Constants qw(:common);
use Apache::File ();
sub handler {
my $r = shift;
return DECLINED unless $r->content_type() eq 'text/html';
my $file = $r->filename;
unless (-e $r->finfo) {
$r->log_error("File does not exist: $file");
return NOT_FOUND;
}
unless (-r _) {
$r->log_error("File permissions deny access: $file");
return FORBIDDEN;
}
my $modtime = localtime((stat _)[9]);
my $fh;
unless ($fh = Apache::File->new($file)) {
$r->log_error("Couldn't open $file for reading: $!");
return SERVER_ERROR;
}
my $footer = <<END;
<hr>
© 2000 <a href="http://samxie.cl.msu.edu">Sam Xie's Footer; </a><br>
<em>Last Modified: $modtime</em>
END
$r->send_http_header;
while (<$fh>) {
s!(</body>)!$footer$1!oi;
} continue {
$r->print($_);
}
return OK;
}
1;
__END__