Re: [cgiapp] coding strategy
Opps, I clicked send prematurely. :-) Brian Parker wrote: > 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 -- > So, the point is, I don't think that a run-mode is a single 'screen' (necessarily). The completion of a run-mode may require show the user several screens to collect all of the information. These screens may be general enough to be used in many different run-modes (across different CgiApp subclasses). I don't like having to put these 'helper screens' in a base class, but it is simplest. BTW, the above example is contrived. On a related note. Do any of you need to show the same 'view' to users from different run modes (across different CgiApp subclasses), without doing a client side redirect? It is simple enough to use the same template from more than one run mode, but there is a certain amount of code that is coupled to a template for loading the correct template variables. I'm trying to come up with a pattern for 'view' classes that are tightly coupled to a template. regards, Brian > > > > > 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]
Re: [cgiapp] coding strategy
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]
[cgiapp] coding strategy
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 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]