Hi All,

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):

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 }
Example of code that calls it in Authen/Authz handlers:
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


In reply to package scoped my() variable in module under mod_perl 5.6 vs 5.8 by njaph

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.