addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

AUTOLOAD and late binding? match vars? params

From: Andy B.
Sent on: Thursday, July 24, 2014 5:10 PM
We have app that overloads Autoload func to use a lookup list for commonly used subs that may not have been require-ed in yet.  It's a little byzantine but, if needed, when Perl hits a unknown function call, the AUTOLOAD function either parses a file (and creates an in-memory list) or checks the list for the function name; if found, it evals a require of the lib file and then eval the function call w/ the pass-ed in params.
                eval ("package $space;require \"$tNode->{FileName}\";");

For instance
my $clean_v = Meta($filename);

Meta() gets found, it's lib "" required and Meta gets called with $filename as the param. It turns out to be a little weird if the call uses a match var:
my $clean_v = Meta($1);

as our AUTOLOAD script does:
        my $func = $AUTOLOAD;
        if(!($func =~ /(.*)::(.*)/)) {
                die("Autoload: parse of $func failed\n");
        my $space = $1;
        $func = $2;

Before the match, @_ (and $1) in AUTOLOAD have the correct value from the original match, (wrap the if { ... }  with
warn("aut: @_ $1 \n");

and I see:
aut: mo mo 
aut: main main
) but afterwards, it's become the namespace matched in the if.  Of course, this only happens if the first use of the autoloaded function happens to use a match var - took a looooong time to debug that one.



Andy Bach,
[address removed]
[masked] cell
[masked] wk

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy