X-Git-Url: http://git.shiar.net/gitweb.cgi/perl/plp/.git/blobdiff_plain/5d1c2193a6c3c98cf426e03eb783eace183e5a0c..68a18bf55edfd520ec9853550b6d718bfb272788:/PLP/Apache.pm diff --git a/PLP/Apache.pm b/PLP/Apache.pm index a18ed25..5a9745c 100644 --- a/PLP/Apache.pm +++ b/PLP/Apache.pm @@ -5,27 +5,44 @@ use strict; our $VERSION = '1.00'; use PLP; -require Apache::Constants; + +use constant MP2 => ( + defined $ENV{MOD_PERL_API_VERSION} and $ENV{MOD_PERL_API_VERSION} >= 2 +); + +BEGIN { + if (MP2) { + require Apache2::Const; + require Apache2::RequestRec; + require Apache2::RequestUtil; + require Apache2::RequestIO; + } else { + require Apache::Constants; + } +} + +our $r; # mod_perl initializer: returns 0 on success, Apache error code on failure sub init { - our $r = shift; + $r = shift; $PLP::print = 'PLP::Apache::print'; + $PLP::read = \&read; $ENV{PLP_FILENAME} = my $filename = $r->filename; unless (-f $filename) { - return Apache::Constants::NOT_FOUND(); + return MP2 ? Apache2::Const::HTTP_NOT_FOUND() : Apache::Constants::NOT_FOUND(); } unless (-r _) { - return Apache::Constants::FORBIDDEN(); + return MP2 ? Apache2::Const::HTTP_FORBIDDEN() : Apache::Constants::FORBIDDEN(); } $ENV{PLP_NAME} = $r->uri; - our $use_cache = $r->dir_config('PLPcache') !~ /^off$/i; -#S our $use_safe = $r->dir_config('PLPsafe') =~ /^on$/i; + $PLP::use_cache = $r->dir_config('PLPcache') !~ /^off$/i; +#S $PLP::use_safe = $r->dir_config('PLPsafe') =~ /^on$/i; my $path = $r->filename(); my ($file, $dir) = File::Basename::fileparse($path); chdir $dir; @@ -35,11 +52,17 @@ sub init { return 0; # OK } +sub read ($) { + my ($bytes) = @_; + $r->read(my $data, $bytes); + return $data; +} + # FAST printing under mod_perl sub print { return unless grep length, @_; PLP::sendheaders() unless $PLP::sentheaders; - $PLP::Apache::r->print(@_); + $r->print(@_); } # This is the mod_perl handler. @@ -51,7 +74,7 @@ sub handler { #S PLP::start($_[0]); PLP::start(); no strict 'subs'; - return Apache::Constants::OK(); + return MP2 ? Apache2::Const::OK() : Apache::Constants::OK(); } 1;