in reply to Re^4 (Third Time): mod_perl and cache?
in thread mod_perl and cache?

Your problem is that you are creating closures in your script. These are not a big problem under CGI because the interpreter exits every time, but under Apache::Registry you have to follow better progamming practices.

Look at your login sub. You use the variable %ARGS in it, but don't pass it to the sub. You are taking advantage of the fact that %ARGS is declared in a higher scope and is thus visible to your subroutine. However, after the first time this gets executed the %ARGS used in the login sub is private and will no longer change.

To fix this, you need to explicitly pass all variables to your subs. Instead of saying &login, say login(\%ARGS) and then read that in at the beginning of the login sub. This is a good programming practice, and you should be doing it anyway.

Note that all of this is explained in the documents that merlyn pointed out to you in the very first post in this thread. You can also read about it in the mod_perl guide.

Replies are listed 'Best First'.
Re^6 (Third Time): mod_perl and cache?
by Flame (Deacon) on Mar 03, 2003 at 20:17 UTC
    Would I need to do the same with %session and $DBH, not to mention the Apache::Request object and the other "globals"?



    My code doesn't have bugs, it just develops random features.

    Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)

      Yes. You should not refer to any lexical variables defined outside the scope of the current sub. Try to code your subs so they are portable enough to be moved to a separate module without changing their code.
        Or he could just our them, I assume?

        Makeshifts last the longest.

        Hmm, Apache::Session works with a tied hash, how could I pass that without loosing the tie? (I did search through perltie, but I didn't find anything.)



        My code doesn't have bugs, it just develops random features.

        Flame ~ Lead Programmer: GMS (DOWN) | GMS (DOWN)