Another possible interaction between object lifetime occurs when there are multiple CGI::Session objects: unless both have identical data, whichever one gets destroyed last, wins. At one point, I added an
END {}
block to a file which had my $session
declared. All of a sudden, that END block kept $session alive until global destruction and the other CGI::Session instance, into which I recorded that a user was in fact logged in, now flushed first. Because the logged-in state was then overwritten by the session visible from the END block (even though the block itself never used it), nobody could log in!Yet another problem happened when I pulled $session out of that code and stored it in a package. The END block had finished its purpose and been deleted, so moving $session to a package once again extended its life to global destruction: a package variable stays around forever, because the package itself is a global resource. However, since the login path had flush() calls carefully placed on it, what broke this time was logout. The delete() call couldn't take effect because the storage was gone by the time the session was cleaned up.
No comments:
Post a Comment