njaph has asked for the wisdom of the Perl Monks concerning the following question:
I'm just starting to test a migration of a mod_perl app from a debian woody (perl 5.6.1, mod_perl 1.26-3.0) to debian sarge (perl 5.8.4, mod_perl 1.29.0.3) and I'm running into a problem with a package level my() variable accessed in package level subs. See below for quick example. This is code I haven't had to touch for 18 months :)
I've had to change the my() to our() but I don't understand why - it feels like I'm missing something very obvious :)
I've had a look at all the perl*delta pod and the changelog for mod_perl and didn't see anything obvious so I'm asking here - your wisdom is appreciated!
The following is part of a simple user details cache module used in an apache auth handler (abbreviated so don't try too hard to syntax check it):
Example of code that calls it in Authen/Authz handlers:package My::Apache::UserCache; use strict; use My::User; require Exporter; our @ISA = qw(Exporter); our @EXPORT_OK = qw(get_pass get_groups); use constant CACHE_TIMEOUT => 60; # seconds my %cache = (); sub fill_cache { my $user = shift; my $now = time; my ($password,@groups) = My::User->get_pw_groups( $user ); # hits DB ... other checks ... $cache{$user} = { timestamp => $now, password => $password, groups => [@groups] }; } sub get_pass { my $user = shift; my $now = time; return $cache{$user}->{password} if $exists_and_hasnt_timed_out_etc; return undef unless fill_cache( $user ); $cache{$user}->{password}; # get direct from cache } sub get_groups { # similar to above }
package My::Apache::UserAuthen; use strict; use My::Apache::UserCache qw(get_pass); ... sub handler { ... setup; get apache basic auth credentials; etc ... my $reason = authenticate( $user, $user_pw ); ... log etc on failure.. return OK; } sub authenticate { my ($user, $user_pw) = @_; ... my $db_pass = get_pass( $user ); ... return messages based on match/mismatch/etc ... return ''; }
Offline using the cache module directly things work fine either way, things work fine in a single page request under 5.6.1/1.26 but the cache variable never keeps values when using my() with a single page request under 5.8.4/1.29. Like I said, changing to it to our() works but why didn't it before?
I use this method for package variables a lot so I'd really like not to have to update and test tens of modules along the way. What, if anything, should I be using instead?
I look forward to hearing peoples suggestions, fixes and opinions - thanks all.
Cheers,
Andrew
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: package scoped my() variable in module under mod_perl 5.6 vs 5.8
by perrin (Chancellor) on Sep 20, 2005 at 04:19 UTC | |
|
Re: package scoped my() variable in module under mod_perl 5.6 vs 5.8
by shenme (Priest) on Sep 20, 2005 at 04:30 UTC | |
by njaph (Initiate) on Sep 20, 2005 at 07:27 UTC | |
|
Re: package scoped my() variable in module under mod_perl 5.6 vs 5.8
by njaph (Initiate) on Sep 21, 2005 at 01:12 UTC | |
by perrin (Chancellor) on Sep 21, 2005 at 15:57 UTC | |
|
Re: package scoped my() variable in module under mod_perl 5.6 vs 5.8
by Errto (Vicar) on Sep 20, 2005 at 15:52 UTC |