Input retrieval differs per server interface, so set $PLP::read to a
function providing a read of specified number of bytes. This differs
from $PLP::print as it's not just a name, because it won't be evalled
but called directly.
our $r = shift;
$PLP::print = 'PLP::Apache::print';
+ $PLP::read = \&read;
$ENV{PLP_FILENAME} = my $filename = $r->filename;
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, @_;
# CGI initializer: opens SCRIPT_FILENAME
sub init {
$PLP::print = 'print';
+ $PLP::read = \&read;
if (defined $ENV{PATH_TRANSLATED}) {
# SCRIPT_* points to handler script (Apache CGI)
$PLP::code = PLP::source($file, 0, undef, $ENV{PLP_FILENAME});
}
+sub read ($) {
+ my ($bytes) = @_;
+ read *STDIN, my $data, $bytes;
+ return $data;
+}
+
# This is run by the CGI script. (#!perl \n use PLP::CGI; PLP::CGI::everything;)
sub everything {
PLP::clean();
return \%post if $ENV{CONTENT_TYPE} !~
m!^(?:application/x-www-form-urlencoded|$)!;
- if ($ENV{MOD_PERL}) {
- $post = Apache->request->content;
- } else {
- read *STDIN, $post, $ENV{CONTENT_LENGTH};
- }
+ $post = $PLP::read->($ENV{CONTENT_LENGTH}) if $ENV{CONTENT_LENGTH};
return \%post unless defined $post and length $post;