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:

my $session = My::Session->new(); my $foo = Foo->new( session => $session ); # and foo creates Bar passing session, which creates # Baz passing session
I would just do something like this:
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.

-derby

In reply to RFC Singleton Sessions by derby

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.