derby has asked for the wisdom of the Perl Monks concerning the following question:
Yes I know the title is kinda convoluted but so is my question/request for comment.
I have a fairly straightforward session class that does the normal web session stuff ala CGI::Session and a database backend. Within the session blob, I store normal stuff like access privs, name, salutation, etc and then store the session id in a cookie.
The problem I have is shimming this into legacy code. Given a cgi process (or mod_perl request), I can set the session cookie appropriately and follow on processes/requests work fine; however, some legacy code needs that initial session information further down the request (same process). Unfortunately, the code is so OO (or that should be overOO'ed) that I would need to modify half a dozen classes to pass the session along.
What I'm thinking of doing is making the session class a singleton so that the new method will return the just created session. So instead of doing something like this:
I would just do something like this:my $session = My::Session->new(); my $foo = Foo->new( session => $session ); # and foo creates Bar passing session, which creates # Baz passing session
my $session = My::Session->new(); my $foo = Foo->new(); ... package Baz; sub new { ... $self->{session} = My::Session->new(); }
Ideally, I'd like to redo the whole app so this isn't a problem, but that's not really feasible. So my question is does this sound feasible? The session class needs to be mod_perl aware but for that, I would just place the singleton reference into pnotes.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RFC Singleton Sessions
by perrin (Chancellor) on Dec 08, 2006 at 01:50 UTC | |
by derby (Abbot) on Dec 08, 2006 at 11:15 UTC | |
by perrin (Chancellor) on Dec 08, 2006 at 15:24 UTC | |
by derby (Abbot) on Dec 08, 2006 at 16:07 UTC | |
|
Re: RFC Singleton Sessions
by skx (Parson) on Dec 08, 2006 at 12:35 UTC |