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', '#00868B', '#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 $calling_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, $href_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mode); my $output = ''; $output .= ''."\n"; $output .= "\n"; $output .= "\n"; $output .= "$that_famous_string\n"; $output .= "\n"; $output .= "\n"; $output .= "Simple Style
\n"; $output .= "$that_famous_string
\n"; $output .= "

$text_this

\n"; $output .= "

$text_called_from

\n"; $output .= "$text_goto_a
\n"; $output .= "$text_goto_b
\n"; $output .= "\n"; $output .= "\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, $href_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mode); 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, $href_goto_b, $text_goto_b) = &get_common_stuff($this_mode, $calling_mode); 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;