[cgiapp] Using CGI::Application with FastCGI and C::A::P::Redirect

Ron Savage ron at savage.net.au
Fri May 23 19:47:44 EDT 2008


Hi Folks

Just for the record, here's a similar program to Dan's, but using
FCGI::ProcManager:

> #!/usr/bin/perl -w
> use strict;
> use FindBin qw($B
> use Webapp;
> use CGI::Fast();
> 
> while (my $q = new CGI::Fast){
>     my $webapp = Webapp->new(
>         QUERY  => $q,
>     );
>     $webapp->run();
> }
> 
> In you application class simply put "return $self->redirect(<URL>)" in 
> our runmodes as you would without FastCGI
> 
> Dan

#!/usr/bin/perl

use strict;
use warnings;

use CGI::Application::Dispatch;
use CGI::Fast;
use FCGI::ProcManager;

# ---------------------

my($proc_manager) = FCGI::ProcManager -> new({processes => 2});

$proc_manager -> pm_manage();

my($cgi);

while ($cgi = CGI::Fast -> new() )
{
        $proc_manager -> pm_pre_dispatch();
        CGI::Application::Dispatch -> dispatch
        (
         args_to_new => {QUERY => $cgi},
         prefix      => 'Local::Application',
         table       =>
         [
          ''         => {app => 'main-menu', rm => 'menu'},
          ':app/:rm' => {},
         ],
        );
        $proc_manager -> pm_post_dispatch();
}

You need the {QUERY => $cgi} code to get access to user-submitted CGI
form variables and their values, since they are captured by the $cgi
object, and so are not available to the default CGI::App $self ->
query() object.

The code above makes the $self -> query() call return the very same $cgi
variable returned by CGI::Fast.

-- 
Ron Savage
ron at savage.net.au
http://savage.net.au/index.html




More information about the cgiapp mailing list