Henry Law <
[email protected]> writes:
On 29/10/2020 14:48, Rainer Weikusat wrote:
# install in the symbol table of the class of
# the invocant under the proper name
#
*{$AUTOLOAD} = $sub;
This is Perl witchcraft, but I followed it and am much better
informed; it's really clever.
One thing, though: in the statement above you're telling Perl that
instead of the AUTOLOAD subroutine it should go straight to the sub
that you built and compiled: I get that.
But I thought $AUTOLOAD was the variable (defined in all the examples
I've seen with "our $AUTOLOAD") not the subroutine? I'm wrong,
plainly, but why?
$AUTOLOAD is a package variable whose value will be the fully qualified
name of the subroutine/ method which was actualy called, eg,
Top::Middle::set_height
This means
*$AUTOLOAD
(the {} aren't really needed)
accesses the glob Top::Middle::set_height via symbolic
reference. Assigning a reference to something to a glob changes the
object in the slot corresponding with the type of the object the
reference refers to. Eg,
[rw@doppelsaurus]/tmp#perl -E '*array = [1,2,3]; say @array'
123
This construct (the $AUTOLOAD one) will not work under 'use
strict'. It'll need a
no strict 'refs';
there (possibly in a block to limit the scope of that).
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)