in reply to Structure of a custom class (using Apache::Session)
My two modules are Object::Generic and Object::Generic::Session. Using them (in HTML::Mason, here) looks something like this:
# -- file httpd.conf -- # (Define the session global.) PerlAddVar MasonAllowGlobals $session # -- file htdocs/autohandler - # (Retrieve the session; process webpage.) % $session = new Object::Session::Generic( % session_config => { Store=>'MySQL', ... }, % cookie_name => 'your cookie name here', % expires => '+8h', % ); % $m->call_next; % $session = undef; # -- file htdocs/file.html -- # (Use the session to access key/value pairs.) <html> % if ($username){ % $session->user( % new Object::Generic( name => $username ) % ); % } % if ($session->user){ Hi <% $session->user->name %>. Welcome back. % } else { <form> Please log in: <input type="text" name="username" /> </form> % } </html> <%args> $username => '' </%args>
You can find Object::Generic and Object::Generic::Session at http://cs.marlboro.edu/code/perl/modules/ if you want to check them out.
Update: I've just uploaded v0.02 of both of these to CPAN.
|
|---|