You can always call the run modes directly by their method names in CGI::Application.
sub rm2_method {
my $self = shift;
my $username = $self->query->param('user');
my $password = $self->query->param('pass');
return $self->rm1_method() unless defined $username and defined $pas
+sword;
$self->authenticate() ? $self->rm4_method() : $self->rm3_method();
}
This way, the get_current_runmode() will always return 'rm2' no matter in what method you are in. To change the current runmode as well you'll use the forward plugin.
use CGI::Application::Plugin::Forward;
sub rm2_method {
my $self = shift;
my $username = $self->query->param('user');
my $password = $self->query->param('pass');
return $self->rm1_method() unless defined $username and defined $pas
+sword;
$self->authenticate() ? $self->forward(rm4') : $self->forward('rm3')
+;
}
First, the get_current_runmode method always returns the new runmode you forward to. If it's authenticated then you get 'rm4', for example. Second, you don't have to remember the method name of that runmode.
But for me, I won't provide rm3 and rm4. I would probably just use the first approach, by calling other methods (not runmode methods) according to the authentication result. Speaking of which, I would just probably using the authentication plugin.
You can also find numerous discussions from super search (don't forget to click the Search button).
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|