[Mpls-pm] Frameworks and session management?

Peter Karman peter at peknet.com
Wed Nov 8 07:34:04 PST 2006



Eric Eklund scribbled on 11/8/06 9:02 AM:
> I am looking to rewrite some old legacy code utilizing either
> CGI::Application or Catalyst.  Looking at the two different frameworks
> will quickly give a Perl novice a headache.  Does anyone have working
> experience with either of these frameworks and session management?  If
> so, would you be willing to share an example.  I have searched the Web
> for tutorials that contain the features I am looking for and have come
> up fairly empty handed.  At this point, I am siding toward CGI::App due
> to the perceived learning curve of Catalyst.
> 

well since I can't do my Cat talk tonight, I'll take a stab at this.

My 2c on whether to use CGI::App or Catalyst is that it depends on how you 
intend to deploy your application. If it's going to be in a shared or 
non-mod_perl environment, then go with CGI::App. If you can run under mod_perl, 
then Cat is a good choice. CGI::App will also run under mod_perl, but Cat does 
not play well as a cgi.

I prefer Cat mostly because of aesthetics. I'm not religious about it; I just 
like the way it makes my apps fit together.

As far as learning curve goes, I think it depends on your previous experience 
(as most things do). I've been working with Cat for about 10 mos and I feel 
comfortable with it now, but the first couple months were tricky. For me though 
it was as much learning best practices and Template Toolkit (to which I was also 
new) as it was nuts and bolts of MVC and the Catalyst Way of Doing Things.

Start here:
http://cgiapp.erlbaum.net/cgi-bin/cgi-app/index.cgi?CatalystCompared
though it's a bit out of date, it's pretty fair.

I find the Cat session handling to be easy and (actually) fun. There are a 
variety of plugins for the session storage backend; I use the DBI version.

My MyApp.pm file looks like:

use Catalyst (
     '-Debug',
     'Browser',
     'Static::Simple',
     'Session',
     'Session::Store::DBI',
     'Session::State::Cookie'
	);


and then my config looks like:

  session => {
      cookie_name => 'myapp_session',
      cookie_expires => 0,        # this is the default (ends with browser close)
      expires        => 8 * 3600, # session ends 8 hours after last access
      dbi_dsn        => 'DBI:mysql:mydbname',
      dbi_user       => 'myuser',
      dbi_pass       => 'mypass',
      dbi_table      => 'sessions',
      verify_address => 0,
      #
      #      do not verify addresses,
      #      since SSL will record different IP for
      #      some proxy users
   }


and then in my Controller code, I can just do:

  my $session = $c->session;	# $s is a hashref of session data
  ...
  # do some stuff, then save something into the session
  $session->{foo} = 'bar';

and it Just Works.


-- 
Peter Karman  .  http://peknet.com/  .  peter at peknet.com


More information about the Mpls-pm mailing list