[id://perrin]. Yep clear. Basically, borrowing from Apache::Singleton, here's the relevant code.

package My::Session; ... use vars qw( $GLOBAL_SESSION ); ... sub new { my( $class, $args ) = @_; $args->{log} ||= My::Log->new(); my $instance = $class->_get_instance( $args ); unless( defined $instance ) { $instance = $class->_new_instance( $args ); $class->_set_instance( $instance ); } return $instance; } sub _get_instance { my( $class, $args ) = @_; if( $ENV{MOD_PERL} ) { $args->{log}->debug( "Getting mod_perl session instance" ); my $req = Apache->request(); my $key = "$class\::_instance"; return $req->pnotes( $key ); } else { $args->{log}->debug( "Getting cgi session instance" ); return $GLOBAL_SESSION; } } sub _new_instance { my( $class, $args ) = @_; my $self = {}; $self->{log} = $args->{log}; $self->{log}->debug( "creating new session instance" ); bless $self, $class; # call method to load access privs here return $self; } sub _set_instance { my( $class, $instance ) = @_; if( $ENV{MOD_PERL} ) { $instance->{log}->debug( "setting new mod_perl instance" ); my $req = Apache->request(); my $key = "$class\::_instance"; $req->pnotes( $key, $instance ); } else { $instance->{log}->debug( "setting new cgi instance" ); $GLOBAL_SESSION = $instance; } }

-derby

In reply to Re^4: RFC Singleton Sessions by derby
in thread 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.