Re: [CDBI] session handling in cdbi
[prev]
[thread]
[next]
[Date index for 2005/10/04]
On Tue, Oct 04, 2005 at 10:51:50AM +0200, Patrik Wallstrom wrote:
> Hi!
>
> I am trying to figure out a smart way of handling permissions in
> Class::DBI. The idea is having a kind of session object and pass that
> around. It is simple of you're only one user using the base class, but
> is really hard if you want to pass around different session
> objects. Has anybody here done that kind of thing? I have been
> searching through the archives and the Wiki but found noting.
Well, here's the approach I tend to use (modelled on dynamic-wind in lisp) -
package MyDB::Session;
use vars qw/$current_session @EXPORT_OK/;
use base qw/Exporter/;
@EXPORT = '&run_with_session';
sub run_with_session {
my ($session, $code) = @_;
local $current_session = $session;
$code->();
}
then in the app code you can just do
run_with_session($session, sub { ... });
and in your underlying classes you just do
my $session = $MyDB::Session::current_session;
Obviously you can clean this up a bit and present a nicer API etc. but that
pretty much covers it.
--
Matt S Trout Specialists in perl consulting, web development, and
Technical Director UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd. mst (at) shadowcatsystems.co.uk for more information
+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +
_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
|
|
Re: [CDBI] session handling in cdbi
Matt S Trout 15:23 on 04 Oct 2005
|