[cgiapp] Re: Unexpected variable persistence with CAD / CADS

Richard Jones ra.jones at dpw.clara.co.uk
Sat Oct 25 08:15:24 EDT 2008


George Hartzell wrote:
> Richard Jones writes:
>  > Mark Stosberg wrote:
>  > 
>  > >> It doesn't seem to happen in an identical setup running under mod_perl, 
>  > >> so I presume it's a 'feature' of the CAD::Server / HTTP::Server. Is this 
>  > >> a known issue, and one of the caveats alluded to in the CAD::Server 
>  > >> docs? Never been a problem for anyone else?
>  > > 
>  > > I haven't used CAD::Server much. Does it also happen with CGI::Application::Server
>  > > ( which I think can also work with Dispatch.pm ) ?
>  > 
>  > Wish I knew. I've never been able to get CA Server working with my 
>  > Dispatch subclass. The exact same dispatch table that works in CAD 
>  > Server returns either a blank page and no error in the console, or an 
>  > error message stating that target must be either a CGI::Application or 
>  > CGI::Application::Dispatch subclass, even though they always are. It's 
>  > probably something I've mis-configured, but I'll keep at it.
>
> You didn't actually provide a broken example, so I cobbled one
> together that I think does what you're describing, but it doesn't
> exhibit the problems you've described.
George, the 'wish I knew' reply was to Mark re the CA::Server failure to 
ever work. I've traced the problem to the lines in handle_request() 
which test $target->isa(), and apparently my targets are neither 
CGI::Application nor CGI::Application::Dispatch subclasses! I just 
cannot fathom this, so I've done a minor modification to the shar to 
load a CGI::Application::Server instead of a 
CGI::Application::Dispatch::Server, which behaves as described. Call 
http://localhost:8080/foo/new_record, or http://localhost:8080/bar and 
observe the console output.

echo c - .
mkdir -p . > /dev/null 2>&1
echo x - ./foo.pl
sed 's/^X//' >./foo.pl << 'END-of-./foo.pl'
Xpackage main;
X
Xuse CGI::Application::Server;
Xmy $server = CGI::Application::Server->new();
X$server->document_root('/tmp');
X$server->entry_points({
X   '/bar' => 'Foo',
X   '/foo' => 'Foo::Dispatch',
X});
X$server->run;
X
END-of-./foo.pl
echo c - ./Foo
mkdir -p ./Foo > /dev/null 2>&1
echo x - ./Foo/Dispatch.pm
sed 's/^X//' >./Foo/Dispatch.pm << 'END-of-./Foo/Dispatch.pm'
Xpackage Foo::Dispatch;
Xuse base 'CGI::Application::Dispatch';
X
Xsub dispatch_args {
X  return {
X      debug => 1,
X      table   => [
X              ':app/:rm' => { },
X              ':app/:rm/:id' => { },
X             ],
X     args_to_new => {
X         PARAMS => { },
X     },
X  };
X}
X
X1;
END-of-./Foo/Dispatch.pm
echo x - ./Foo.pm
sed 's/^X//' >./Foo.pm << 'END-of-./Foo.pm'
Xpackage Foo;
Xuse base CGI::Application;
X
Xsub setup {
X  my $self = shift;
X  $self->start_mode('new_record');
X  $self->run_modes(
X           'new_record' => 'new_record',
X          );
X}
X
Xsub new_record {
X  my $self = shift;
X  my $vars = $self->query->Vars;
X
X  $vars->{id} = $self->param('id') if $self->param('id');
X  return "<pre>new_record param('id'): " . $self->param('id') . "</pre>"
X    . $self->dump_html;
X}
X
X1;
END-of-./Foo.pm
exit


-- 
Richard Jones



More information about the cgiapp mailing list