if we'll see into perlref.pod and search for substring {CODE}
and read around a bit, then we'll calmly understand that
we're able to do following trick:
use strict;
package main;
sub AUTOLOAD {
return 'old-main-autoload';
}
package mypackage;
# let's capture that ::AUTOLOAD
my $aasub = *{$::{AUTOLOAD}}{CODE};
# now let's, as we decided earlier, have it overloaded
*::AUTOLOAD = sub {
# here how we overload it:
print "do first\n";
#call old one and print that returned value inside '[]'
print '[', $aasub->(), "]\n";
print "do last\n";
};
package main; # again
flurfish_sub();
in my case output is
do first
[old-main-autoload]
do last
But my personal advice - you're moving to C-like area or even
assembler code catching area when
you will really soon will complicate logic.
I think when you will see that code in your program
then it is a good signal to redesign your code.
:)
Best wishes,
Vadim.
|