boboson has asked for the wisdom of the Perl Monks concerning the following question:
Is there a way to init my variables and then if they change they are changed but if not, they are left alone?
here are some code to achieve the above:
this code works but there must be a better way of doing this!
# application object my $self = shift; # get cgi query object my $q = $self->query(); my %post = $q->Vars; # if entries_per_page is not empty: set value, if it's empty and sessi +on value is empty: init session value if($post{'entries_per_page'}){ $self->session->param('entries_per_page' => $post{'entries_per_pag +e'}); } elsif( (!$post{'entries_per_page'}) && (!$self->session->param('entr +ies_per_page')) ) { $self->session->param('entries_per_page' => 10); }
2) In the CGI::Application framework is all the functions such as: setup(), cgiapp_init(), teardown() etc. executed every time the application is run? Or is there anywhere I can init stuff just once?
3) In my run_modes function:
is there any way I can pass in parameters to the called function? for example a static page argument on which page to print to the printStaticPage function?$self->run_modes( 'static_page' => 'printStaticPage', 'AUTOLOAD' => 'showErrorPage' );
I don't want to use code like:
# page if($post{'page'} eq "about"){ # print page about } elsif($post{'page'} eq "purchase"){ # print page purchase } elsif($post{'page'} eq "contact"){ # print page contact } else { # print deault page }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: init session variables
by PodMaster (Abbot) on Feb 08, 2005 at 07:34 UTC | |
|
Re: init session variables
by ikegami (Patriarch) on Feb 08, 2005 at 07:14 UTC |