[cgiapp] cgi::application::dispatch under PSGI

Rhesa Rozendaal perl at rhesa.com
Tue Feb 28 14:33:34 EST 2012


On 02/28/2012 05:45 PM, Kurt Lidl wrote:
> Greetings.
>
> I've got a large application that is running under mod_perl, running on
> Apache 2.2.22.
> Everything is working OK there.  It uses CGI::Application::Dispatch as
> its invocation
> method.

I'm using roughly the same stack, though I use starman in dev, and 
intend to do so in prod as well (behind an apache reverse proxy).

> I became interested in making that application work under PSGI.  Since
> that is
> now supported natively by modern versions of CGI::Application, I figured
> it shouldn't
> be too hard to make this work.

It's not hard, but I found out it takes jumping through some hoops.

> I've got a dead-simple .psgi file:
>
> --- snip, snip ---
> use lib ('..');
>
> use Data::Dump qw(dump ddx);
> use CWS1::Dispatch;
>
> CWS1::Dispatch->as_psgi;
> --- snip, snip ---

Here's mine, using your class name as example:

--- snip, snip ---
use CWS1::Dispatch;
use CGI::PSGI;

my $cgiapp = sub {
     my $env = shift;
     CWS1::Dispatch->as_psgi(
     args_to_new => {
         QUERY     => CGI::PSGI->new($env),
     })->($env);
};
--- snip, snip ---

The key here is that I found I needed to make sure each request gets a 
fresh instance of a CGI::PSGI object.


> In my Dispatch.pm file, I have this:

Mine is the same (in structure).

There's nothing specific in my regular apps, and I do receive params 
from CA::Dispatch. So I think you'll get it working in your situation 
too, as long as you make sure you pass in a fresh CGI::PSGI object every 
time.

rhesa


More information about the cgiapp mailing list