[Catalyst] Authenticating a "Normal CGI Script" Inside a Catalyst Application

Yuval Kogman nothingmuch at woobling.org
Sat Jan 28 02:30:35 CET 2006


On Fri, Jan 27, 2006 at 20:09:11 -0500, hkclark at gmail.com wrote:
> Hi Yuval,
> 
> Thank you very much for the suggestions.  I have been taking a look at
> HTTP::Request::AsCGI and have a few questions:
> 
> 1) It seems the whole idea of HTTP::Request::AsCGI is to essentially grab
> what CGI.pm would normally send to stdout and capture it in a string
> variable -- is that correct?  I assume the idea with Catalyst would be to
> assign this captured output to something like $context->response->body so
> that it goes back to the user.  Or am I totally missing the boat here?

You are correct, but it's not only that - HTTP::Request::AsCGI also
takes an HTTP::Request object (presumably Catalyst::Request can be
fudged into one - ask sri on how) and sets up an environment in
which a CGI script can be executed and the results can be gathered.

This includes everything from $ENV{QUERY_STRING} to localized STDIN
and STDOUT.

> 
> 2) This could be a really dumb question, but when I look at the "Synopsis"
> example in:
> http://search.cpan.org/~chansen/HTTP-Request-AsCGI-0.5/lib/HTTP/Request/AsCGI.pm
> I'm confused by what a GET request to http://www.host.com has to do with
> capturing the output of the CGI.pm header, start_html, h1, and end_html call
> a few lines later.  I see that $request is used in the AsCGI constructor,
> but it seems totally unnecessary and unrelated.  What am I missing here?

The SYNOPSIS section takes the HTTP::Request object created using
->new( GET => $uri ), and then uses that to create an environment
using the HTTP::Request::AsCGI object.

When CGI->new is created, CGI will look at the environment, and be
fooled into thinking that it's serving the request for
"http://www.host.com/".

Then, after 'my $c' goes out of scope the environment is restored,
and the while loop prints out the output of the CGI script to the
real stdout.

The point is that CGI->new could happen in an entirely different
process - HTTP::Request::AsCGI sets up the environment to act as if
it was an HTTP server that is handling a CGI script.


-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /me does not drink tibetian laxative tea: neeyah!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060128/cd1c1221/attachment.pgp


More information about the Catalyst mailing list