Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Suggestions for a web survey framework

by leocharre (Priest)
on Oct 16, 2009 at 18:51 UTC ( [id://801624]=note: print w/replies, xml ) Need Help??


in reply to Suggestions for a web survey framework

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.

Replies are listed 'Best First'.
Re^2: Suggestions for a web survey framework
by skx (Parson) on Oct 17, 2009 at 15:33 UTC
Re^2: Suggestions for a web survey framework
by stonecolddevin (Parson) on Oct 16, 2009 at 19:04 UTC

    This works too, minus the gruesome HTML in code bit :-)

    mtfnpy

Re^2: Suggestions for a web survey framework
by Anonymous Monk on Oct 16, 2009 at 19:17 UTC
    Excellent- thank you so much, this looks right and I like what I see from the plugins.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://801624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-03-28 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found