Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
The problem is that although the login sub is inherited/invoked, the program seems to exit from there. By what mechanism does the app return to the original runmode invoked by the initial cgi script ('show_survey')? Do I have to store the initial value as a webapp param (if so, where? the MyApp or MyAuth module?)and then execute that runmode from the login sub? I'm pleased with the progress so far. Hopefully this is just something silly I'm overlooking. Thanks for your continued patience.
Here is the revised code:cgi script
#!/usr/local/bin/perl use MyApp; my $webapp = MyApp->new(); $webapp->start_mode('show_survey'); $webapp->run;
authentication C::A
package MyAuth; use base 'CGI::Application'; use strict; use warnings; sub cgiapp_init { my $self = shift; # set the name of the run mode CGI param $self->mode_param('rm'); # shared run modes $self->run_modes([ 'login', 'AUTOLOAD' ]); } sub cgiapp_prerun { my $self = shift; my $runmode = shift; my $authorized = $self->param('authorized'); unless ($authorized) { $self->prerun_mode( 'login' ); } } sub login { my $self = shift; my ($error) = @_; my $output = "<p><H3>sub MyAuth::login entered</H3></p>"; my %params; $params{'ERROR'} = $error if defined($error); # load/process login template # for test purposes assume user authenticates successfully $self->param('authorized', 1); $output .= $self->dump_html(); return $output; } sub AUTOLOAD { my $self = shift; my $output = "<p><H3>sub MyAuth::AUTOLOAD entered</H3></p>"; $output .= "<p><H3>### ERROR - Invalid runmode '" . $self->mode_param('rm') . "'</H3></p>"; return $output; } 1;
survey C::A
package MyApp; use base 'MyAuth'; use strict; use warnings; sub setup { my $self = shift; my $output = "<p><H3>sub MyApp::setup entered</H3></p>"; $self->start_mode('show_survey'); $self->run_modes([ 'show_survey', 'save_survey' ]); return $output; } sub show_survey { my $self = shift; my $output = "<p><H3>sub MyApp::show_survey entered</H3></p>"; return $output; } sub save_survey { my $self = shift; my $output = "<p><H3>sub MyApp::save_survey entered</H3></p>"; return $output; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Structuring multiple CGI::Application modules II
by dragonchild (Archbishop) on Jun 28, 2004 at 17:37 UTC | |
by Anonymous Monk on Jun 28, 2004 at 22:19 UTC | |
by dragonchild (Archbishop) on Jun 29, 2004 at 02:30 UTC |