note
ikegami
<p>Your problem has nothing to do with either <c>UNIVERSAL</c> or <c>AUTOLOAD</c>. You're seeing that behaviour because your <c>AUTOLOAD</c> was built in package <c>main</c>. Examine the following:
<c>
sub Test1::print_context {
print(__PACKAGE__, "\n");
}
{
package Test2;
sub print_context {
print(__PACKAGE__, "\n");
}
}
Test1::print_context(); # main
Test2::print_context(); # Test2
</c>
<p>Fixed code:
<c>
#!/usr/bin/perl -w
{
package UNIVERSAL;
use Carp;
sub AUTOLOAD {
carp "foo";
}
}
bar();
</c>
554088
554088