[cgiapp] changing app modes during cgiapp_prerun

Lee Carmichael lecar_red at yahoo.com
Wed Jul 23 13:05:31 EDT 2008


Hello Amelia,

Since you are still in that run mode, you can't logically change it until the prerun finishes. The prerun_mode only changes the mode after the all the preruns get called so without mucking around with the internal data structure (which is a bad idea) it won't change. ( this also makes sure plugins have a more predictable state)

I guess I could see trying to save a bit of processing by validating data then changing the run mode and running more validation instead of doing a redirect. I think logically this get complex and difficult to debug very quickly. 

As an idea, you could have the code check the value in the prerun_mode. Something like:

sub cgiapp_prerun {
   my $self = shift;

   if ( ! $self->valid_for_rm ) {
     $self->prerun_mode('mode2');
   }

   if ( ! $self->validate_more ) { 
     $self->prerun_mode('mode3');
   } 
}

sub validate_more { 
   my $self = shift;
   my $rm  = $self->prerun_mode || $self->get_current_mode;

   ## do validation based upon rm
}


Without knowing more of what your trying to do I'm not sure I would recommend this. In general i think its preferrable to issue a redirect and let the next request do the next series of processing. Or use a dispatch table or code ref for run mode parameter lookup to change pages if that is what your trying to do. I think this would be less confusing down the road, IMHO.

Hope this helps,

Lee


----- Original Message ----
From: Amelia Ireland <amelia.ireland at gmail.com>
To: CGI Application <cgiapp at lists.openlib.org>
Sent: Tuesday, July 22, 2008 2:45:16 PM
Subject: [cgiapp] changing app modes during cgiapp_prerun

Hi,

I was wondering if there is a way to immediately change the run mode  
during cgiapp_prerun. If I change it using prerun_mode, the run mode  
(as reported by get_current_runmode) doesn't actually change until  
cgiapp_prerun is finished. This is causing me a problem with some data  
validation that I am doing.

Thanks,
Amelia.

--
Amelia Ireland
GO Editorial Office
http://www.ebi.ac.uk || http://www.berkeleybop.org
BBOP Plant Project: http://bbopgarden.blogspot.com






#####  CGI::Application community mailing list  ################
##                                                            ##
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
##                                                            ##
##  Web archive:  http://lists.openlib.org/pipermail/cgiapp/   ##
##  Wiki:          http://cgiapp.erlbaum.net/                 ##
##                                                            ##
################################################################


More information about the cgiapp mailing list