From: Christian Hansen Date: Sun, 16 Oct 2005 01:28:18 +0000 (+0000) Subject: Added simple IO test X-Git-Tag: v1.0~58 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTTP-Request-AsCGI.git;a=commitdiff_plain;h=128529591fd44541f66ab7d92ae78845ffe584a1 Added simple IO test --- diff --git a/MANIFEST b/MANIFEST index 50b0070..6a48266 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,5 +1,6 @@ lib/HTTP/Request/AsCGI.pm t/01use.t +t/04io.t Makefile.PL MANIFEST This list of files META.yml Module meta-data (added by MakeMaker) diff --git a/lib/HTTP/Request/AsCGI.pm b/lib/HTTP/Request/AsCGI.pm index 4f65de3..1b0526c 100644 --- a/lib/HTTP/Request/AsCGI.pm +++ b/lib/HTTP/Request/AsCGI.pm @@ -75,10 +75,10 @@ sub setup { if ( $self->request->content_length ) { - $self->stdin->write( $self->request->content ) - or croak("Can't write content: $!"); + $self->stdin->syswrite( $self->request->content ) + or croak("Can't write content to stdin: $!"); - seek( $self->stdin, 0, 0 ) + $self->stdin->sysseek( 0, SEEK_SET ) or croak("Can't seek stdin: $!"); } @@ -109,7 +109,16 @@ sub restore { open( STDERR, '>&', $self->{restore}->{stderr} ) or croak("Can't restore stderr: $!"); - + + $self->stdin->sysseek( 0, SEEK_SET ) + or croak("Can't seek stdin: $!"); + + $self->stdout->sysseek( 0, SEEK_SET ) + or croak("Can't seek stdout: $!"); + + $self->stderr->sysseek( 0, SEEK_SET ) + or croak("Can't seek stderr: $!"); + $self->{restored}++; } @@ -149,8 +158,6 @@ HTTP::Request::AsCGI - Setup a CGI enviroment from a HTTP::Request # enviroment and descriptors will automatically be restored when $c is destructed. } - $stdout->seek( 0, 0 ); - while ( my $line = $stdout->getline ) { print $line; } diff --git a/t/04io.t b/t/04io.t new file mode 100644 index 0000000..e5c4539 --- /dev/null +++ b/t/04io.t @@ -0,0 +1,25 @@ +#!perl + +use Test::More tests => 3; + +use strict; +use warnings; + +use HTTP::Request; +use HTTP::Request::AsCGI; + +my $r = HTTP::Request->new( POST => 'http://www.host.com/'); +$r->content('STDIN'); +$r->content_length(5); +$r->content_type('text/plain'); + +my $c = HTTP::Request::AsCGI->new($r)->setup; + +print STDOUT 'STDOUT'; +print STDERR 'STDERR'; + +$c->restore; + +is( $c->stdin->getline, 'STDIN', 'STDIN' ); +is( $c->stdout->getline, 'STDOUT', 'STDOUT' ); +is( $c->stderr->getline, 'STDERR', 'STDERR' );