After recently reading some nodes here that talked about CGI::Application, I decided to go play with it and see how it worked. On the whole, I'm quite pleased; I can certainly see myself using it in future projects. There is, however, something about its behaviour that I don't quite understand.

Here's the stripped-down code I'm playing with:

CGIApp.pl
#! /usr/bin/perl use lib '.' ; use CGIApp ; my $cgiapp = CGIApp->new() ; $cgiapp->run() ;

CGIApp.pm
package CGIApp; use base 'CGI::Application'; use strict; sub setup { my $self = shift ; $self->start_mode('mode1') ; $self->mode_param( 'runmode' ) ; $self->run_modes( 'mode1' => 'foo', 'mode2' => 'bar', 'mode3' => 'zoot' ); } sub foo { my $self = shift ; my $q = $self->query() ; my $output = '' ; $output .= $q->start_html( "Foo" ) ; $output .= $q->h2( 'I\'m webapp run mode number one.' ) ; $output .= $q->h2( 'I like to frolick in the sun.' ) ; $output .= $q->start_form ; $output .= $q->h3( 'Gimme a number!' ) ; $output .= $q->textfield( -name => 'first_number' ); $output .= $q->hidden(-name => 'runmode', -value => 'mode2' ); $output .= $q->submit(); $output .= $q->end_form(); $output .= $q->end_html(); return $output; } sub bar { my $self = shift ; my $q = $self->query() ; my $output = '' ; my $first_number = $q->param( 'first_number' ) ; $output .= $q->start_html( "Bar" ) ; $output .= $q->h2( 'I\'m webapp run mode number two.' ) ; $output .= $q->h2( 'You click me and I\'ll click you!' ) ; $output .= $q->start_form ; $output .= $q->h3( 'Gimme another number!' ) ; $output .= $q->textfield( -name => 'second_number' ); $output .= $q->hidden( -name => 'first_number', -value => $first_number ); $output .= $q->hidden( -name => 'runmode', -value => 'mode3' ); $output .= $q->submit(); $output .= $q->end_form(); $output .= $q->end_html(); return $output; } sub zoot { my $self = shift ; my $q = $self->query() ; my $output = '' ; my $first_number = $q->param( 'first_number' ) ; my $second_number = $q->param( 'second_number' ) ; $output .= $q->start_html( "Zoot" ) ; $output .= $q->h2( 'I\'m webapp run mode number three.' ) ; $output .= $q->h2( 'Adding\'s why you called on me!' ) ; $output .= $q->pre( $first_number . ' + ' . $second_number . ' = ' . $first_number + $second_number ) ; return $output; } 1 ;

What I had hoped to see was the program prompt for a number, prompt for a second number, then display the sum. Instead, when the second number is submitted, runmode 2 (bar) is reloaded.

I think there is something I'm not getting about how this module works, or how it's intended to work. Could someone kindly fill me in?

Much thanks,

_______________
D a m n D i r t y A p e
Home Node | Email

In reply to CGI::Application Run Modes by DamnDirtyApe

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.