in reply to handling __WARN__ funkiness

I'm willing to bet your signal handler is being overwritten by someone else. To find out what is stomping on your __WARN__ handler, tie the signal handler hash to a simple Tie::StdHash with a bit of reporting to see where else people are changing $SIG{__WARN__}.

Here is my solutino that will find you where your __WARN__ handle is getting overwritten.

TheLoader.pm
package Report; use Tie::Hash; our @ISA = 'Tie::StdHash'; sub TIEHASH { my $storage = bless {}, shift; $storage } sub STORE { my ($this, $key, $value) = @_; my (@foo) = caller(); my ($package, $filename, $line) = caller; print STDERR "Storing $key => $value in $this at $package, in $fil +ename on line $line.\n"; $this->{$key} = $value } package TheLoader; use strict; use warnings; tie %SIG, 'Report'; $SIG{__WARN__} = sub { return if $_[0] =~ /inherited AUTOLOAD/; print STDERR 'stolen warn: ' . $_[0]; }; package UNIVERSAL; sub AUTOLOAD { print "AUTOLOAD\n"; } 1;
BTW, this was tested with blah.pl:
use strict; use warnings; use Bar; use Foo; foo(); warn "hi"; Foo::bar(); warn "hi";
Foo.pm
package Foo; sub bar { $SIG{__WARN__} = sub { 0; }; } 1;
And Bar.pm
use strict; use warnings; package Bar; use TheLoader; foo(); warn "hi"; warn "inherited AUTOLOAD here";
When run here, blah.pl gives:
Storing __WARN__ => CODE(0x818e988) in Report=HASH(0x818e14c) at TheLo +ader, in TheLoader.pm on line 29. AUTOLOAD stolen warn: hi at Bar.pm line 8. AUTOLOAD stolen warn: hi at blah.pl line 7. Storing __WARN__ => CODE(0x818cf68) in Report=HASH(0x818e14c) at Foo, +in Foo.pm on line 4. AUTOLOAD AUTOLOAD AUTOLOAD

Replies are listed 'Best First'.
Re^2: handling __WARN__ funkiness
by xevian (Sexton) on Oct 11, 2005 at 14:59 UTC
    Thanks cazz, using tie I was able to "hijack" the other people setting up a __WARN__ signal handler, and verify that the message wasn't the deprecation message before calling theirs. Works like a champ!