[cgiapp] Re: Unexpected variable persistence with CAD / CADS
Richard Jones
ra.jones at dpw.clara.co.uk
Sat Oct 25 06:11:53 EDT 2008
George Hartzell wrote:
> 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.
>
> I've stuck a shar archive of a little app on the end of this message.
>
> http://localhost:8080/foo/update/2
>
> followed by
>
> http://localhost:8080/foo/new_record
>
> does not seem to have a stuck id value.
>
> Does it have the problem on your system?
>
> If not, can you figure out how to make it have the problem?
Yes!! Just put a PARAMS entry in Dispatch:
sub dispatch_args {
return {
table => [
':app/:rm' => { },
':app/:rm/:id' => { },
],
args_to_new => {
PARAMS => { foo => 'bar' }, # <= comment to change behaviour
},
};
}
Your example app. will now exhibit the described behaviour just using:
http://localhost:8080/foo/new_record
http://localhost:8080/foo/new_record/123
http://localhost:8080/foo/new_record
Even an empty PARAMS arg (PARAMS => {}) switches on variable
persistence. See also the debug output to console to see the id param
presence in every request.
Not sure if this is the intended behaviour, but presumably means it's
not possible to use the PARAMS arg in args_to_new - at least not without
being very careful and fully aware of the consequences.
Just as an exercise - I'd never encountered a shar before - I've
modified your original for the minimal complexity required to
demonstrate the 'misbehaviour':
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::Dispatch::Server;
X
Xmy $server =
X CGI::Application::Dispatch::Server->new(
X class => 'Foo::Dispatch',
X root_dir => '/tmp',
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('update');
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