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)...


Rich36
There's more than one way to screw it up...


In reply to Passing values between run modes in CGI::Application by Rich36

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.