Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI::Application 'No such run mode...'

by Anneq (Vicar)
on Dec 23, 2003 at 23:40 UTC ( #316750=perlquestion: print w/ replies, xml ) Need Help??
Anneq has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying out CGI::Application for the first time and used the sample code from an on-line course:

Web Server Progamming - CGI, Part 3
package MyWebApp; use base 'CGI::Application'; use HTML::Template; # sub cgiapp_init { # # Called automatically right before setup(). # # Optional Initialization Hook # # Receives as its params, all the arg which were sent to new( +) # } sub setup { my $self = shift; $self->start_mode('mode1'); # $self->mode_param('rm'); $self->run-modes( 'mode1' => 'simplePage', 'mode2' => 'mode2', 'mode3' => 'mode3' ); # $self = param( # 'pageID' => 'default', # # baseFone, bgColor, DarkTone, Midtone, LightTone, TextColor # 'userDisplayPrefs' => ['5', 'white', '#00008B', '#0086 +8B', '#EEE8AA', '#606060'] # ); } # sub cgiapp_prerun { # # }; sub get_common_stuff { my $this_mode = shift; my $calling_mode = shift; my @other_modes; @other_modes = (2, 3) if ($this_mode ==1); @other_modes = (1, 3) if ($this_mode ==2); @other_modes = (1, 2) if ($this_mode ==3); my $text_this = "This is run mode $this_mode"; my $text_called_from = "This mode was called from run mode $callin +g_mode"; my $href_goto_a = 'mywebapp.pl?rm=mode'.$other_modes[0].'&calling_ +mode='.$this_mode; my $text_goto_a = "To to run mode $other_modes[0]"; my $href_goto_b = 'mywebapp.pl?rm=mode'.$other_modes[1].'&calling_ +mode='.$this_mode; my $text_goto_b = "Go to run mode $other_modes[1]"; return ($text_this, $text_called_from, $href_goto_a, $text_goto_a, + $href_goto_b, $text_goto_b); } # sub teardown { # Reserved for Future Use # my $self = shift; # # # Do things teardownish, like: # # Output to log file # # Close files or dBs # # Store info about the app to the server # } sub simplePage { my $this_mode = 1; my $self = shift; my $q = $self->query(); my $calling_mode = $q->param("calling_mode"); my $that_famous_string = 'Hello, world!'; my ($text_this, $text_called_from, $href_goto_a, $text_goto_a, $hr +ef_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mod +e); my $output = ''; $output .= '<!DOCTYPE HTML PUBLIC "-//IETF/DTD HTML/EN">'."\n"; $output .= "<html>\n"; $output .= "<head>\n"; $output .= "<title>$that_famous_string</title>\n"; $output .= "</head>\n"; $output .= "<body>\n"; $output .= "<i>Simple Style</i><br>\n"; $output .= "<b>$that_famous_string</b><br>\n"; $output .= "<p>$text_this</p>\n"; $output .= "<p>$text_called_from</p>\n"; $output .= "<a href=\"$href_goto_a\">$text_goto_a</a><br>\n"; $output .= "<a href=\"$href_goto_b\">$text_goto_b</a><br>\n"; $output .= "</body>\n"; $output .= "</html>\n"; # my $pageID = $q -> param('pageID'); # my $userDisplayPrefs = $q -> param('userDisplayPrefs'); # printContents formats the output for simplePages based on # params # my $outpout = $q -> printContents($pageID); return $output; } sub mode2 { my $this_mode = 2; my $self = shift; my $q = $self->query(); my $calling_mode = $q->param("calling_mode"); my $that_famous_string = 'Hello, world!'; my ($text_this, $text_called_from, $href_goto_a, $text_goto_a, $hr +ef_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mod +e); my $output = ''; $output .= $q->start_html(-title => $that_famous_string); $output .= $q->i("CGI.pm-style")."\n"; $output .= $q->br."\n"; $output .= $q->b($that_famous_string)."\n"; $output .= $q->br."\n"; $output .= $q->p($text_this)."\n"; $output .= $q->p($text_called_from)."\n"; $output .= $q->a({href=>$href_goto_a}, $text_goto_a)."\n"; $output .= $q->br."\n"; $output .= $q->a({href=>$href_goto_b}, $text_goto_b)."\n"; $output .= $q->end_html()."\n"; return $output; } sub mode3 { my $this_mode = 3; my $self = shift; my $q = $self->query(); my $calling_mode = $q->param("calling_mode"); my $that_famous_string = 'Hello, world!'; my ($text_this, $text_called_from, $href_goto_a, $text_goto_a, $hr +ef_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mod +e); my $output = ''; my $template = HTML::Template->new(filename=>'mywebapp.tmpl.html') +; $template -> param( THAT_FAMOUS_STRING => $that_famous_string, TEXT_THIS => $text_this, TEXT_CALLED_FROM => $text_called_from, HREF_GOTO_A => $href_goto_a, TEXT_GOTO_A => $text_goto_a, HREF_GOTO_B => $href_goto_b, TEXT_GOTO_B => $text_goto_b ); $output .= $template->output; return $output; } 1;

I got the following error:

CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

Tue Dec 23 18:16:13 2003 mywebapp.pl: No such run-mode 'mode1' at C:/Perl/site/lib/CGI/Application.pm line 133

I've tried code samples from other sources as well and got the same result.

After super-searching here, Google and other Perl sites, I didn't find any similar errors.

Does anyone know what the problem could be? Any help on this would be appreciated

Regards,

Anne

Merry Christmas Monks.

Comment on CGI::Application 'No such run mode...'
Download Code
Re: CGI::Application 'No such run mode...'
by jgallagher (Pilgrim) on Dec 23, 2003 at 23:50 UTC
    From the tutorial you linked, the relavent code is:
    sub setup {     my $self = shift;     $self->start_mode('mode1');     $self->run_modes(        'mode1' => 'helloworld_cgi_app1',        'mode2' => 'helloworld_cgi_app2',        'mode3' => 'helloworld_cgi_app3',        ); }
    The error comes because 'mode1' is not defined in your setup function - the hash passed to run_modes sets up the "Oh, I got the run mode parameter 'mode1'; which function do I call now?" part of CGI::Application. I don't see off the top of my head why cutting and pasting wouldn't work, so if you could show us your code, that would help. :-)
Re: CGI::Application 'No such run mode...'
by freddo411 (Chaplain) on Dec 24, 2003 at 00:18 UTC
    You don't say how you invoke your test program. Did you do something like:

    http://you.com/foo.pl

    or

    http://you.com/foo.pl?rm=mode1

    try out the later, along with rm=mode2 , etc.

    I also noticed that in your simplePage sub you are writing the header. This is incorrect, CGI::App takes care of this.

    -------------------------------------
    Nothing is too wonderful to be true
    -- Michael Faraday

      freddo411,

      Thanks for your response:

      You don't say how you invoke your test program. Did you do something like:
      http://you.com/foo.pl
      or
      http://you.com/foo.pl?rm=mode1
      try out the later, along with rm=mode2 , etc.

      In get_common_stuff(), two links are defined and called by other subroutines (modes). The user would select a link with a href like: mywebapp.pl?rm=mode'....


      I also noticed that in your simplePage sub you are writing the header. This is incorrect, CGI::App takes care of this.

      Actually, this sample code shows three different ways to make use of combinations of CGI::Application, CGI.pm and CGI::Template. Its quite a handy reference for me, but as you say, it doesn't appear to be using CGI::Application as it was intended.

      Regards,

      Anne

Re: CGI::Application 'No such run mode...'
by jsprat (Curate) on Dec 24, 2003 at 04:46 UTC
    You're going to kick yourself...

    run-modes should be run_modes. (Note the _underscore_)

    HTH..

      I spent hours trying to figure this one out.


      Excuse me a minute while I kick myself......OW!!!!!!


      Thank you jsprat for looking over my shoulder.


      Anne

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://316750]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (14)
As of 2014-12-18 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (58 votes), past polls