http://www.perlmonks.org?node_id=316750

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.