diff options
Diffstat (limited to 'CGI')
-rw-r--r-- | CGI/Emulate/PSGI.pm | 23 |
1 files changed, 22 insertions, 1 deletions
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__ |