On Friday, January 4, 2002, at 02:22 AM, Ken Williams wrote: > For the sake of thread completion, here's a script which demonstrates > the bug. It turns out to be a Perl bug (5.6.1, at least), not an > Apache::Session bug. I'll post to p5p after I post here.
I was surprised to find the "it's not a bug, it's a feature" defense on p5p. So here's an update. The following is either a workaround, or the proper fix, depending on what you think Perl's proper behavior should be. ;-) { local *session; tie %session, 'Apache::Session::MySQL', ...; ... } The "local *session;" is the important bit. It doesn't work to do "local %session;", because %session will still be tied even after it goes out of scope, and thus the hash data will never get written to storage. In a Mason context, which is where I'm using it, I do this in my top-level autohandler (ignore the main:: subroutines, they're just for pedagogy): <%init> # 'local' so it's available to lower-level components local *session; my $dbh = &::get_dbh; my $session_id = &::get_cookie('_session_id'); tie %session, 'Apache::Session::MySQL', $session_id, {Handle => $dbh, LockHandle => $dbh}; ... </%init> -Ken