Much fun was had today. I needed some session management for a site with vague specs and I'm not sure what data to capture. I generally don't enjoy stuffing too much data into a session, but I needed to get this stuff running quickly, with the caveat that other pages on this site might want to share the session id to avoid setting multiple cookies. But if I do that, how do easily prevent accidentally overwriting session data in the database?
My sessions now have their own namespaces. It's based on CGI::Session and is mostly transparent to the programmer. You can have 28 different programs setting a session parameter named "total", all of them using the same session, but each maintaining a distinct total, if necessary. But if they need to share the data? Create a new session object explicitly naming the namespace from which you want to get the data:
my $session = My::Session->new($cgi, 'some_namespace');
If you leave the namespace off, it defaults to sprintf("%s::%s", $0, $calling_package);.
I'm not entirely sure that's a great idea, but it's quite handy.