Commit info for scoop/lib:
Modified Files:
Scoop.pm
Log Message:
Adding a Scoop::Session module, which removes the dependency on
Apache::Session. This one doesn't use deadlock-prone locking as the previous
one did, and seems to perform better (in a simple benchmark). It should also be
compatible with most databases without any changes, as it uses simple queries.
Also updated sessionreap cron to work with the new session table.
There's no migration script; it's not worth the effort. Users will just have to
log back in.
Index: Scoop.pm
===================================================================
RCS file: /cvs/scoop/scoop/lib/Scoop.pm,v
retrieving revision 1.133
retrieving revision 1.134
diff -r1.133 -r1.134
186c186
< tied(%{$self->{SESSION}})->delete;
---
> $self->session->flush;
214a215
> $self->session->cleanup;
255a257
> =item $S->session
258,260c260,264
< A generic interface to Apache::Session. It just takes a key and optionally
< some data (which can be any scalar. References allowed), and returns the data
< (if given only a key) or sets the data, and returns the key you gave it.
---
> Provides access to session data. Without arguments, it returns the
> Scoop::Session object for this request. Otherwise, it acts as a shortcut method
> and compatibility layer. Giving only B<name> is the same as calling
> C<$S->session->fetch(B<name>)>. Giving both B<name> and B<value> is the same as
> calling C<$S->session->store(B<name>, B<value>)>.
268,288c272,274
< my ($key, $data) = @_;
< my $return;
<
< if ($data) {
<
< # First see if we have a session
< unless ($S->{SESSION_KEY}) {
< # No? Then create one, because now we need it.
< warn " (Scoop::session) No session record. Creating one.\n" if ($DEBUG);
< $S->_create_session_record();
< # Now go ahead
< }
<
< $S->{SESSION}->{$key} = $data;
< $return = $key;
< } else {
< $data = $S->{SESSION}->{$key};
< $return = $data;
< }
<
< return $return;
---
> return $S->{SESSION} unless @_;
> return $_[1] ? $S->{SESSION}->store($_[0], $_[1])
> : $S->{SESSION}->fetch($_[0]);
327a314,317
> # do cookie-related things. moved here from ApacheHandler so that boxes can
> # create sessions and have them persist
> $S->_handle_cookies();
>
917c907
<
---
>
920c910
<
---
>
923c913
<
---
>
925,926d914
< # NOTE: see Scoop::Cookies about why it checks two keys. Compatibility is
< # the short answer. XXX - remove the second check after awhile
928c916
< $self->{SESSION_KEY} = $cookie_jar->{$cookie_name} || $cookie_jar->{session} || undef;
---
> $self->{SESSION_KEY} = $cookie_jar->{$cookie_name} || undef;
930,932c918,922
<
< undef my (%session);
<
---
>
> # create the object now. if we get a session id, then we'll tell the object
> # about it later
> $self->{SESSION} = Scoop::Session->new(scoop => $self);
>
939,989c929,933
< # Otherwise, go ahead and tie the session.
< $self->_create_session_record($self->{SESSION_KEY});
< return $self;
< }
<
< sub _create_session_record {
< my $self = shift;
< my $key = shift;
< undef my (%session);
<
< # Otherwise, make session hash
< unless (
< eval {
< tie %session, 'Apache::Session::MySQL', $key, {
< Handle => $self->dbh,
< LockHandle => $self->dbh
< };
< }) {
< warn " (Scoop::_create_session_record) Invalid session cookie: $@" if $DEBUG;
< $self->{EXPIRE_SESSION} = 1;
< tie %session, 'Apache::Session::MySQL', undef, {
< Handle => $self->dbh,
< LockHandle => $self->dbh
< };
< }
<
< # make Session a member of $self
< $self->{SESSION} = \%session;
< $self->{SESSION_KEY} = $self->session('_session_id');
< warn " (Scoop::_create_session_record) SESSION KEY is $self->{SESSION_KEY}" if $DEBUG;
<
< $self->_timestamp_session();
< warn " (Scoop::_create_session_record) Timestamped session: ",$self->session('TIME'),"\n" if ($DEBUG);
< return $self;
< }
<
< sub _timestamp_session {
< my $self = shift;
< my $stamp = time;
< $self->session("TIME", $stamp);
< return;
< }
<
< sub _get_cookies {
< my $self = shift;
< my $cookie = shift;
< my @cookies = split /;\s*/, $cookie;
< my $cookie_jar = {};
< foreach my $cookie_crumb (@cookies) {
< my ($name, $val) = split /=/, $cookie_crumb;
< $cookie_jar->{$name} = $val;
---
> # attach the existing session to the session object. if it fails, then the
> # session key is invalid and we need to expire the cookie that gave us a
> # bad key
> unless ($self->{SESSION}->session_id($self->{SESSION_KEY})) {
> $self->{EXPIRE_SESSION} = 1;
992c936
< return $cookie_jar;
---
> return $self;
1080c1024
< warn "Session ".$self->session('_session_id').", UID ".$self->session('UID') if $DEBUG;
---
> warn "Session ".$self->session->session_id.", UID ".$self->session('UID') if $DEBUG;
1087c1031
< $self->session('UID', $uid);
---
> #$self->session('UID', $uid);