John Coy wrote:
> Greetings all,
>
> I am relatively new to CGI::Application, although I'm not
> new to Perl and to CGI scripts in general. I am curious
> if there is a "style guide" or a recommened method for
> implementing actions whose user-supplied input can possibly
> change the "run method"
>
> For example, a common issue with respect to web input is
> verification of user data (ie: are all fields present, is the
> right type of data in each field, etc). Based on the outcome
> of this verification, you may need to go to a different "screen"
> which is handled by a different "run mode" in the CGI::Application
> model.
>
I'm working through similar problems right now. The way I have been
doing this is as follows. Assume a contrived fictional banking
application. Also, 'setTmplVar' and 'process_tmpl' are my own subclass
methods that use 'Template-Toolkit', there purpose should be fairly
obvious to 'HTML-Template' users.
This is a run-mode:
-- begin code --
sub showAccountTransactions {
my $self = shift;
my $q = $self->query();
my $account_number = $q->param('account');
# if the $account_number is invalid show a 'screen' that
# that will prompt the user for a correct a account number
# and then continue back to this same run-mode.
my $account_obj = Account->retrieve($account_number)
or return $self->showGetValidAccountNumAndContinue(
"Account: $account_number is invalid. Please choose a
correct one."
);
...
# add some objects to the 'template context'
...
return $self->process_tmpl('showAccountTransations.tmpl');
}
-- end code --
'showGetValidAccountNumAndContinue' would be a method of my base class
which is general enough to be used from many different CgiApp subclasses.
It is a 'screen' that is designed to simply collect an account number and
continue (back to the same attempted run-mode). It looks something like
this.
-- begin code --
sub showGetValidAccountNumAndContinue {
my ($self,$message) = @_;
$self->setTmplVar('message' => $message);
my @account_objs = Account->retrieve_all();
$self->setTmplVar('accounts' => \@account_objs);
return $self->process_tmpl('chooseStream.html');
}
-- end code --
>
> I'm curious if cgiapp_prerun is the "right" place to do this
> type of thing? Is it stylistically ok to perform various check
> functions based on the run mode passed to cgiapp_prerun()?
>
> I'm also curious about any "gotchas" of calling one run mode
> subroutine from another? For example, based on the value of
> a "submit" button, one run mode may need to toss the activity
> to another run mode. Again, is this better handled in
> cgiapp_prerun() or is it ok to do it in the run mode subroutine?
>
> Assistance is greatly appreciated and I'll be glad to forward
> code snippets if that would be helpful.
>
> Thanks!
>
> ---
> John Coy
> CTO/VP Network Operations
> ANCI/Arkansas.Net
>
> ---------------------------------------------------------------------
> Web Archive: http://www.mail-archive.com/cgiapp@lists.vm.com/
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]