--- /dev/null
+This file documents the revision history for Perl extension HTTP::Request::AsCGI.
+
+0.01 2005-10-21 00:00:00 2005
+ - first release
-lib/HTTP/Request/AsCGI.pm
+Changes
examples/daemon.pl
examples/mechanize.pl
examples/synopsis.pl
+lib/HTTP/Request/AsCGI.pm
+Makefile.PL
+MANIFEST This list of files
+META.yml Module meta-data (added by MakeMaker)
+README
t/01use.t
t/04io.t
t/05env.t
-Makefile.PL
-MANIFEST This list of files
-META.yml Module meta-data (added by MakeMaker)
requires:
Carp: 0
Class::Accessor: 0
- File::Temp: 0.14
- IO::Handle: 0
+ HTTP::Request: 0
+ HTTP::Response: 0
+ IO::File: 0
distribution_type: module
generated_by: ExtUtils::MakeMaker version 6.17
Carp => 0,
Class::Accessor => 0,
HTTP::Request => 0,
+ HTTP::Response => 0,
IO::File => 0
}
);
--- /dev/null
+NAME
+ HTTP::Request::AsCGI - Setup a CGI enviroment from a HTTP::Request
+
+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.
+ }
+
+ while ( my $line = $stdout->getline ) {
+ print $line;
+ }
+
+DESCRIPTION
+ Provides a convinient way of setting up an CGI enviroment from a
+ HTTP::Request.
+
+METHODS
+ new ( $request [, key => value ] )
+ Contructor, first argument must be a instance of HTTP::Request
+ followed by optional pairs of environment keys and values.
+
+ enviroment
+ Returns a hashref containing the environment that will be used in
+ setup. Changing the hashref after setup has been called will have no
+ effect.
+
+ setup
+ Setups the environment and descriptors.
+
+ restore
+ Restores the enviroment and descriptors. Can only be called after
+ setup.
+
+ request
+ Returns the request given to constructor.
+
+ response
+ Returns a HTTP::Response. Can only be called after restore.
+
+ stdin
+ Accessor for handle that will be used for STDIN, must be a real
+ seekable handle with an file descriptor. Defaults to a tempoary
+ IO::File instance.
+
+ stdout
+ Accessor for handle that will be used for STDOUT, must be a real
+ seekable handle with an file descriptor. Defaults to a tempoary
+ IO::File instance.
+
+ stderr
+ Accessor for handle that will be used for STDERR, must be a real
+ seekable handle with an file descriptor.
+
+THANKS TO
+ Thomas L. Shinnick for his valuable win32 testing.
+
+AUTHOR
+ Christian Hansen, "ch@ngmedia.com"
+
+LICENSE
+ This library is free software. You can redistribute it and/or modify it
+ under the same terms as perl itself.
+
sub _make_request {
my ( $self, $request ) = @_;
- $self->cookie_jar->add_cookie_header($request) if $self->cookie_jar;
+ if ( $self->cookie_jar ) {
+ $self->cookie_jar->add_cookie_header($request);
+ }
my $c = HTTP::Request::AsCGI->new($request)->setup;
$response->content( $response->error_as_HTML );
}
else {
- $response = $c->restore->response;
+ $response = $c->restore->response;
}
$response->header( 'Content-Base', $request->uri );
$response->request($request);
- $self->cookie_jar->extract_cookies($response) if $self->cookie_jar;
+
+ if ( $self->cookie_jar ) {
+ $self->cookie_jar->extract_cookies($response);
+ }
+
return $response;
}
sub new {
my $class = shift;
my $request = shift;
+
+ unless ( @_ % 2 == 0 && eval { $request->isa('HTTP::Request') } ) {
+ croak(qq/usage: $class->new( \$request [, key => value] )/);
+ }
my $self = {
request => $request,
$stdout = $c->stdout;
- # enviroment and descriptors will automatically be restored when $c is destructed.
+ # enviroment and descriptors will automatically be restored
+ # when $c is destructed.
}
while ( my $line = $stdout->getline ) {
=head1 DESCRIPTION
+Provides a convinient way of setting up an CGI enviroment from a HTTP::Request.
+
=head1 METHODS
=over 4
-=item new
+=item new ( $request [, key => value ] )
+
+Contructor, first argument must be a instance of HTTP::Request
+followed by optional pairs of environment keys and values.
=item enviroment
+Returns a hashref containing the environment that will be used in setup.
+Changing the hashref after setup has been called will have no effect.
+
=item setup
+Setups the environment and descriptors.
+
=item restore
+Restores the enviroment and descriptors. Can only be called after setup.
+
=item request
+Returns the request given to constructor.
+
=item response
+Returns a HTTP::Response. Can only be called after restore.
+
=item stdin
+Accessor for handle that will be used for STDIN, must be a real seekable
+handle with an file descriptor. Defaults to a tempoary IO::File instance.
+
=item stdout
+Accessor for handle that will be used for STDOUT, must be a real seekable
+handle with an file descriptor. Defaults to a tempoary IO::File instance.
+
=item stderr
-=back
+Accessor for handle that will be used for STDERR, must be a real seekable
+handle with an file descriptor.
-=head1 BUGS
+=back
-=item THANKS TO
+=head1 THANKS TO
Thomas L. Shinnick for his valuable win32 testing.