From: Christian Hansen Date: Sun, 16 Oct 2005 00:48:25 +0000 (+0000) Subject: Added a SYNOPSIS X-Git-Tag: v1.0~59 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FHTTP-Request-AsCGI.git;a=commitdiff_plain;h=bd7813ac79640bd1b9996b3fb9d9d67d185e6c48 Added a SYNOPSIS --- diff --git a/Makefile.PL b/Makefile.PL index 427a757..b91523b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -8,7 +8,7 @@ WriteMakefile( PREREQ_PM => { Carp => 0, Class::Accessor => 0, - File::Temp => 0.14, - IO::Handle => 0 + HTTP::Request => 0, + IO::File => 0 } ); diff --git a/lib/HTTP/Request/AsCGI.pm b/lib/HTTP/Request/AsCGI.pm index 9d062a2..4f65de3 100644 --- a/lib/HTTP/Request/AsCGI.pm +++ b/lib/HTTP/Request/AsCGI.pm @@ -5,8 +5,7 @@ use warnings; use base 'Class::Accessor::Fast'; use Carp; -use IO::Handle; -use File::Temp; +use IO::File; __PACKAGE__->mk_accessors( qw[ enviroment request stdin stdout stderr ] ); @@ -19,9 +18,9 @@ sub new { my $self = { request => $request, restored => 0, - stdin => File::Temp->new, - stdout => File::Temp->new, - stderr => File::Temp->new + stdin => IO::File->new_tmpfile, + stdout => IO::File->new_tmpfile, + stderr => IO::File->new_tmpfile }; $self->{enviroment} = { @@ -125,10 +124,37 @@ __END__ =head1 NAME -HTTP::Request::AsCGI - Create a CGI enviroment from a HTTP::Request +HTTP::Request::AsCGI - Setup a CGI enviroment from a HTTP::Request =head1 SYNOPSIS + use CGI; + use HTTP::Request; + use HTTP::Request::AsCGI; + + my $request = HTTP::Request->new( GET => 'http://www.host.com/' ); + my $stdout; + + { + my $c = HTTP::Request::AsCGI->new($request)->setup; + my $q = CGI->new; + + print $q->header, + $q->start_html('Hello World'), + $q->h1('Hello World'), + $q->end_html; + + $stdout = $c->stdout; + + # enviroment and descriptors will automatically be restored when $c is destructed. + } + + $stdout->seek( 0, 0 ); + + while ( my $line = $stdout->getline ) { + print $line; + } + =head1 DESCRIPTION =head1 METHODS @@ -137,6 +163,8 @@ HTTP::Request::AsCGI - Create a CGI enviroment from a HTTP::Request =item new +=item enviroment + =item setup =item restore