logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

HTTP::Request::AsCGI - Set up a CGI environment from an HTTP::Request

Authors

       Christian Hansen <ch@ngmedia.com> Hans Dieter Pearcey <hdp@cpan.org>

Description

       Provides a convenient way of setting up an CGI environment from an HTTP::Request.

Methods

       new ( $request [, key => value ] )
           Constructor.   The  first argument must be a instance of HTTP::Request, followed by optional pairs of
           environment key and value.

       environment
           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
           Sets up the environment and descriptors.

       restore
           Restores the environment 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.

Name

       HTTP::Request::AsCGI - Set up a CGI environment from an HTTP::Request

See Also

       examples directory in this distribution.
       WWW::Mechanize::CGI
       Test::WWW::Mechanize::CGI

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;

               # environment and descriptors will automatically be restored
               # when $c is destructed.
           }

           while ( my $line = $stdout->getline ) {
               print $line;
           }

Thanks To

       Thomas L. Shinnick for his valuable win32 testing.

Version

       version 1.2

See Also