[cgiapp] cgi::application::dispatch under PSGI
Kurt Lidl
kurt.lidl at cello.com
Tue Feb 28 11:45:43 EST 2012
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 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.
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 ---
It is invoked in the httpd.conf like this:
<LocationMatch "^/cws1/(?!static/).*$">
SetHandler perl-script
PerlHandler Plack::Handler::Apache2
PerlSetVar psgi_app /path/to/websvc/CWS1/CWS1.psgi
Order allow,deny
Allow from all
</LocationMatch>
In my Dispatch.pm file, I have this:
--- snip, snip ---
package CWS1::Dispatch;
use base qw(CGI::Application::Dispatch::PSGI);
use strict;
use warnings;
no warnings 'redefine';
sub dispatch_args {
return {
prefix => 'CWS1',
args_to_new => {
TMPL_PATH => $ENV{CgiAppBaseDir} . "/CWS1_TMPL",
PARAMS => {
CWS_loctheme => "tundra",
}
},
table => [
'' => {
app => 'Login',
rm => 'start'
},
'login/:rgroup/:locnickname' => {
app => 'Login',
rm => 'start'
},
':app' => { },
':app/:rm' => { },
],
};
}
1;
--- snip, snip ---
I've worked through taking most of the mod_perl-ism's out of the code,
and replacing them
with plain old CGI::Application ways of doing things. Mostly centered
around not doing:
$self->query->headers_out->add('Content-Length' => $length);
but rather:
$self->header_add('-Content_Length' => $length);
Anyhow... The problem that I've run into is accessing runmodes through
the Dispatch table, I don't seem
to get any param values filled out in my runmode. For example, I used
to access
.../cws1/login/foo/bar
and then could access $self->param('rgroup') and
$self->param('locnickame') and get
back 'foo' and 'bar' respectively.
Under the as_psgi invoked server, I don't have any values in the param
data structure.
Did I miss something obvious in how this is supposed to work under PSGI?
Thanks for any insight.
-Kurt
More information about the cgiapp
mailing list