www.frotzware.com

Perl symbol table diagnostics, or unwanted AUTOLOADER invocation. PDF Print E-mail
Written by Frotz   
Tuesday, 12 September 2006
SCENARIO: You have identical test invocation code, but one instance works and the other attempts to invoke the AUTOLOADER. (The answer is really stupid, but the diagnostic is pretty cool.)

Unwanted AUTOLOADER invocations

This just happened to me. I'd been working on a module inside a rich framework that has a base-class AUTOLOADER. I had several methods that had similar invocation guards, but one method hit the AUTOLOADER while all of the others hit my methods, as expected.

Diagnostics

At first, I was fairly confused (I usually am;-)). Then I tried to use a local exception class with stack trace generation capabilities to get a clue as to why I ended up in the base class' AUTOLOADER rather than in my derived class' explicitly defined method.

Unfortunately, this didn't provide me any information or insight that the Perl debugger using the EMACS perldb-mode didn't already show me. It just formatted the stack trace nicely.

Next, I tried to interrogate the symbol table to understand why my problem method was not being called. Trying to find the information was interesting. I expected hits in "Perl Best Practices" and "Perl Hacks" under "type-glob", but instead, the reference "symbol" was what gave me the clue I needed ("Perl Hacks", "Hack 75", page 192, cf: "%main::".

Finding this crucial piece of information allowed me to write the following diagnostic script:

use SOME::DEEP::PACKAGE;
use Data::Dumper;

print "1 - ", Dumper( \%main:: ), "\n";

Upon seeing the output, this grew to:

use SOME::DEEP::PACKAGE;
use Data::Dumper;

print "1 - ", Dumper( \%main:: ), "\n";
print "2 - ", Dumper( \%SOME:: ), "\n";

The predictable final form was:

use SOME::DEEP::PACKAGE;
use Data::Dumper;

print "1 - ", Dumper( \%main:: ), "\n";
print "2 - ", Dumper( \%SOME:: ), "\n";
print "3 - ", Dumper( \%SOME::DEEP:: ), "\n";
print "4 - ", Dumper( \%SOME::DEEP::PACKAGE:: ), "\n";

The results of entry 4 showed that my method was indeed missing.

And now for the stupid part...

Trying to understand what fat-finger mistake I'd made, I looked at the source file. I found that as I had cut and pasted a common EXCEPTION: section of my POD documentation, I had inadvertently doubled up the "=cut" lines. (I would never have seen it without the EMACS font-lock (syntax coloring).) Removing the extraneous "=cut" line resolved my problem, but the symbol table diagnostics exercise will prove to be extremely valuable in some of my other projects that rely on symbol table interrogations.

 
< Prev   Next >