SteveS832001 has asked for the wisdom of the Perl Monks concerning the following question:

I started using CGI::Application to rewrite one of my cgi applications that I have. I haven't seen an example of a more complex application then the one on the man page that had 3 run modes. What I want to know is how do I jump around the run modes. For example I have one rm (run mode) that is a basic form page the asks for the username and password. when they click on submit it goes to rm 2 which checks the username and password. Then rm 2 decides which rm to send the user too. If the username and password are correct send to rm 4 if username and password are wrong send to rm 3 if no username and passwords are defined send to rm 1. I don't fully understand CGI::Application yet so if you know where some good examples are please post them too.

Also rm 2 does not have anything to display all it does is process the info.
  • Comment on CGI::Application trouble understanding it.

Replies are listed 'Best First'.
Re: CGI::Application trouble understanding it.
by derby (Abbot) on Sep 11, 2007 at 17:27 UTC

    No ... I think you understand CGI::Application ... but your confusing runmodes with the view portion of MVC - runmodes map to controller methods, not views. So from the scenario you present, I'm not seeing anything out of the ordinary.

    -derby

    update:: Have you taken a look at CGI::Application's homepage and mailing list archive?

    update again: Specifically, this thread

Re: CGI::Application trouble understanding it.
by naikonta (Curate) on Sep 11, 2007 at 17:59 UTC
    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!