From f863c838292faeeafdd7e5bf781b717e9c3d6510 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 5 Dec 2014 16:50:19 +0100 Subject: CGI::Emulate::PSGI: fix uwsgi support https://github.com/tokuhirom/p5-cgi-emulate-psgi/pull/3 --- CGI/Emulate/PSGI.pm | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/CGI/Emulate/PSGI.pm b/CGI/Emulate/PSGI.pm index 335d6c0..27f42cb 100644 --- a/CGI/Emulate/PSGI.pm +++ b/CGI/Emulate/PSGI.pm @@ -21,7 +21,8 @@ sub handler { { local %ENV = (%ENV, $class->emulate_environment($env)); - local *STDIN = $env->{'psgi.input'}; + local *STDIN; + tie (*STDIN, 'CGI::Emulate::PSGI::Handle', $env->{'psgi.input'}); local *STDOUT = $stdout; local *STDERR = $env->{'psgi.errors'}; @@ -54,6 +55,26 @@ sub emulate_environment { return wantarray ? %$environment : $environment; } +package CGI::Emulate::PSGI::Handle; + +require Tie::Handle; +our @ISA = qw(Tie::Handle); + +sub READ { + my $self = shift; + my $bufref = \$_[0]; + my (undef, $len, $offset) = @_; + my $buf; + my $ret = $$self->read($buf, $len, $offset); + $$bufref = $buf; + $ret; +} + +sub TIEHANDLE { + my ($class, $ref) = @_; + bless \$ref, shift +} + 1; __END__ -- cgit v1.2.3-1-g7c22