From 4565100c67dd7b0344e9eb332296d5fa64e7611b Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Tue, 2 Oct 2007 12:08:26 +0200 Subject: [PATCH] generalize reading post input 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. --- PLP/Apache.pm | 7 +++++++ PLP/CGI.pm | 7 +++++++ PLP/Fields.pm | 6 +----- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/PLP/Apache.pm b/PLP/Apache.pm index c388095..bc78881 100644 --- a/PLP/Apache.pm +++ b/PLP/Apache.pm @@ -26,6 +26,7 @@ sub init { our $r = shift; $PLP::print = 'PLP::Apache::print'; + $PLP::read = \&read; $ENV{PLP_FILENAME} = my $filename = $r->filename; @@ -49,6 +50,12 @@ 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, @_; diff --git a/PLP/CGI.pm b/PLP/CGI.pm index 9b72355..56ca4db 100644 --- a/PLP/CGI.pm +++ b/PLP/CGI.pm @@ -9,6 +9,7 @@ use PLP; # 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) @@ -57,6 +58,12 @@ sub init { $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(); diff --git a/PLP/Fields.pm b/PLP/Fields.pm index 2a4190c..7f07c4e 100644 --- a/PLP/Fields.pm +++ b/PLP/Fields.pm @@ -27,11 +27,7 @@ sub doit { 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; -- 2.30.0