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 $filename 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;
####
use strict;
use warnings;
use Bar;
use Foo;
foo();
warn "hi";
Foo::bar();
warn "hi";
####
package Foo;
sub bar {
$SIG{__WARN__} = sub { 0; };
}
1;
####
use strict;
use warnings;
package Bar;
use TheLoader;
foo();
warn "hi";
warn "inherited AUTOLOAD here";
####
Storing __WARN__ => CODE(0x818e988) in Report=HASH(0x818e14c) at TheLoader, 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