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

George Hartzell hartzell at alerce.com
Tue Oct 21 22:13:10 EDT 2008


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.

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?

g.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	.
#	./foo.pl
#	./Foo
#	./Foo/Dispatch.pm
#	./Foo.pm
#
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	 };
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		   'update' => 'update',
X		   'new_record' => 'new_record',
X		  );
X}
X
Xsub update {
X  my $self = shift;
X  my $vars = $self->query->Vars;
X
X  if ( my $id = $self->param('id') ) {
X    $vars->{id} = $id; # should only contain a value if an update req.
X    print STDERR "My update-param id is: " . $self->param('id') . "\n";
X    print STDERR "My update-vars id is: " . $vars->{id} . "\n";
X  }
X  # update db with content of $vars;
X}
X
Xsub new_record {
X  my $self = shift;
X  my $vars = $self->query->Vars;
X
X  if ($self->param('id')) {
X    $vars->{id} = $id; # should only contain a value if an update req.
X    print STDERR "My new_record-param id is: " . $self->param('id') . "\n";
X    print STDERR "My new_record-vars id is: " . $vars->{id} . "\n";
X  }
X  else {
X    print STDERR "No id.\n";
X  }
X}
X
X
X1;
END-of-./Foo.pm
exit



More information about the cgiapp mailing list