Use CGI::Application with CGI::Application::Plugin::Session

pseudocode...

package MyApp; use base 'CGI::Application'; use CGI::Application::Plugin::Session; use CGI::Application::Plugin::AutoRunmode; sub setup { my $self = shift; $self->start_mode('home'); } # this method is a "runmode" a "screen view" if you will sub home : Runmode { my $self = shift; $self->have_basic_info or return $self->forward('basic_info'); ... } sub basic_info : Runmode { my $self = shift; return q{<form> name: <input name="name" value=""> <input type="hidden" name="rm" value="_basic_info_save"> ... }; } sub _basic_info_save : Runmode { my $self = shift; $self->query->param('name') or die('missing name'); $self->session->param('name' => $self->query->param('name') ); ... } # this method is not a runmode : sub have_basic_info { my $self = shift; # LOOK: you don't worry about instancing the session object, about +making # sure who it's for, etc etc-- you just freaking call self->session +() # and your object is there- cookies set.. the works- all for you! $self->session->param('name') ? 1 : 0; }

And in your cgi-bin/myapp.cgi ...

#!/usr/bin/perl use MyApp; my $app = MyApp->new; $app->run; # DONE

There's a learning curve. But this is hands down the fastest way to do it, while doing it "right". CGI::Application and plugins do so much work for you that it's just hard to believe such few lines of code do so damn much.. as mentioned, you don't see there instancing of the session object, setting the cookie, retrieving it.. It's done *for* you. It's really very nice.

And the code you're using has been tested retested debugged and redebugged by a legion of extremely talented people much wiser than you or I! :-)

You can use the session object as is with defaults, or you can tweak it to all heck- timeout, expiry.. etc. Just like you would a CGI::Session object- which is what you get. The plugin manages that object.

If you want to learn it as fast as possible, look up the docs to the mentioned modules, read it all top to bottom- and give it a try.


In reply to Re: Suggestions for a web survey framework by leocharre
in thread Suggestions for a web survey framework by Anonymous Monk

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.