[cgiapp] RFC: first-class support for PSGI in CGI::Application
Mark Stosberg
mark at summersault.com
Sat Feb 13 19:20:01 EST 2010
> I've tried reading the PSGI docs a number of times, but my head swims
> because of the quantity of apparently-disparate modules.
>
> What I'd like is to see /how to/ convert a
> CGI::Application::Dispatch-based script into a *::PSGI, including
> configuring the web server.
>
> I don't want a statement: It can be done. I'm sure it can be done, but a
> step-by-step recipe is what I'm after.
>
> And I don't want to be hammered with a list of possibilities. I want (to
> start with) just one way which actually works.
Ron,
The way I would like to document for you doesn't exist yet, because
support has not yet been built directly into CGI::Application and
CGI::Application::Dispatch.
Here's some instructions that I think could work right now, using Apache
and mod_cgi.
First, the web server configurations would be the same as they are now
for CGI::Application::Dispatch: You would set up some mod_rewrite rules
that pass requests on to the dispatcher if the request is for file or
directory which does not physically exist. The details of that are in
the ::Dispatch documentation.
Then your dispatch.cgi could look like this:
use Plack::Handler::CGI;
use CGI::Application::Dispatch::PSGI;
use WebApp::Dispatch;
Plack::Handler::CGI->new->run(
WebApp::Dispatch->as_psgi
);
Some notes about this:
- This is not the way that the Plack documentation would prefer that you
do it. It advocates foremost a more abstracted approach of using a
".psgi" file, which could be loaded and run without modification with
all handlers that Plack supports. For an application that is designed
to run in one environment, I see this as unnecessary complexity.
- CGI::Application::Dispatch::PSGI has a couple of drawbacks which would
be addressed by adding core support to CGI::Application and
::Dispatch:
- It ineffectively allows headers to fully generated, only to reparse
them back to the required PSGI data structure, only to have
regenerated a moment later by PSGI back to proper headers. With core
support, headers could generated once, not twice.
- It locks you into using CGI::PSGI as the query object (which means
you are using CGI.pm). Although no other CGI.pm-like options exist
now that support CGI, this is something that I would like
CGI::Application to support, so that CGI::Simple::PSGI will one day
be an option, for example.
Mark
--
http://mark.stosberg.com/
More information about the cgiapp
mailing list