Tricky AUTOLOAD behavior

From: Jim Schueler (jschueler_at_tqis.com)
Date: 08/25/04


Date: 24 Aug 2004 19:47:25 -0700

Here is some sample code that uses inherited class methods:

package parseHTML ;

sub parseHTML::docomment {
        my $comment = shift ;
        print $comment, "\n" ;
        }

package parseASP ;

sub parseASP::AUTOLOAD {
        use vars qw( $AUTOLOAD ) ;

        my $key = $AUTOLOAD ;
        my $package = __PACKAGE__ ;
        $key =~ s/^${package}::// ;

        eval "parseHTML::$key( \@_ )" ;
        }

sub parseASP::doParse () {
        ...
        local $/ = undef ;
        $content = []
        $buf = <HTMLFILE> ;
        $buf =~ s|<!--(.*?)-->|'<!-- '.&docomment( $1, $comments ).'-->'|seig
        ...
        }

sub parseASP::docomment {
        my $comment = shift ;
        print $comment, "\n" ;
        }

&parseASP::doParse() ;

The code listed above works fine, outputting each comment of an HTML file.

If I delete the last function, parseASP::docomment(), then the inherited
function parseHTML::docomment() should behave identically. However, this
time, the code outputs a bunch of blank lines.

My best theory is that the first argument, $1, is passed as a reference to a
local special variable that goes out of scope. But common sense tells me that
anything that goes on the stack should still be there when I pull it off.
Having lost my mind trying to figure this out, any insight or explanation
would be greatly appreciated.

 -Jim