I am probably overlooking something here:
I am using CGI::Application framework and CGI::Session
I need to set some init values for my session variables. These values will ofcourse change over the session. How to I prevent the values from being initiated everytime the user reloads the page?

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:

$self->run_modes( 'static_page' => 'printStaticPage', 'AUTOLOAD' => 'showErrorPage' );
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?

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 }

In reply to init session variables by boboson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.