Rich36 has asked for the wisdom of the Perl Monks concerning the following question:
I'm in the process of writing my first app with CGI::Application. So far, it's working pretty well and I understand most of it. What's tripping me is up is trying to figure out how to share values between run modes. What I'm trying to do in the code below is set the values in the first run mode so that the values are visible in the second. For example, $self->param('foo') gets defined in the first run mode, the value can be referenced in the second.
I understand that you can set params in the setup sub and have them be visible to all the run modes, but how do you then change that value?
package Testing; use base 'CGI::Application'; use strict; use warnings; use diagnostics; sub setup { my $self = shift; $self->start_mode('cast'); $self->mode_param('rm'); $self->tmpl_path('/home/users/rich36'); $self->run_modes( 'cast' => 'castVotes', 'list' => 'listVotes' ); #$self->param('badcomments' => ""); # ??? #$self->param('goodcomments' => ""); # ??? } sub castVotes() { my $self = shift; # Get the CGI query object my $q = $self->query(); # Set the params - these are the ones I'm trying to get to in the +other run mode... $self->param( 'name' => $q->param('name'), 'id' => $q->param('id'), 'ip' => $q->param('ip'), ); # Code to validate values passed by the query string #.... # Returns HTML::Template output return $output; } sub listVotes() { my $self = shift; # Get the CGI query object my $q = $self->query(); # This doesn't work.... # I need to be able to access the values stored in # $self in the other run mode. my $name = $self->param('name'); my $id = $self->param('id'); my $ip = $self->param('ip'); } 1;
Any help would be greatly appreciated. Also, ++ rob_au for the excellent module review/tutorial (CGI::Application)...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing values between run modes in CGI::Application
by rob_au (Abbot) on Apr 12, 2002 at 07:35 UTC | |
by Rich36 (Chaplain) on Apr 12, 2002 at 13:27 UTC |