in reply to Detect a localized variable

I want My::Cache to complain (and refuse to force refreshing) if someone starts modifying the variable without using local.

Um, no you don't, that sounds like horrible API design :)

$ perl use Devel::Peek; use Scalar::Util qw' refaddr '; our $snot = 66; Dump $snot; warn refaddr \$snot; local $snot = 77; Dump $snot; warn refaddr \$snot; __END__ SV = IV(0x99acf8) at 0x99acfc REFCNT = 1 FLAGS = (IOK,pIOK) IV = 66 10071292 at - line 5. SV = IV(0x3f8c58) at 0x3f8c5c REFCNT = 1 FLAGS = (IOK,pIOK) IV = 77 4164700 at - line 8. $ perl -le " print 0x3f8c5c 4164700 $ perl -le " print 0x99acfc 10071292

Replies are listed 'Best First'.
Re^2: Detect a localized variable
by Anonymous Monk on Nov 18, 2011 at 13:47 UTC
    $ perl -e " our $snot = 66; push @snot, \$snot; local $snot = 77; push + @snot, \$snot; print qq[$_ $$_\n] for @snot " SCALAR(0x99aa64) 66 SCALAR(0x3f8cc4) 77
Re^2: Detect a localized variable
by Sewi (Friar) on Nov 18, 2011 at 13:58 UTC
    I don't like the idea, too, but I know that not taking care about this issue will lead to big problems in the future, mainly due to high time pressure and partly due to the skill level of the people who should use it :-).