hurricup has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks!

In the SelfLoader.pm I found AUTOLOAD block name. Syntax is familiar with BEGIN/CHECK/etc. but autoloading being done using AUTOLOAD sub as far as i know. What is it?

Replies are listed 'Best First'.
Re: AUTOLOAD block
by dave_the_m (Monsignor) on Jul 05, 2015 at 19:34 UTC
    It's just a subroutine. The special subs, such as BEGIN, DESTROY, AUTOLOAD, etc, don't need to be prefixed with the 'sub' keyword.
    $ perl -MO=Deparse -e'AUTOLOAD { }' sub AUTOLOAD { } -e syntax OK

    Dave.

      Didn't know that, thanks. Which blocks exactly work this way except I know about: BEGIN, UNITCHECK, CHECK, INIT, END, AUTOLOAD, DESTROY

        Hello hurricup,

        Which blocks exactly work this way...[?]

        There is a non-exhaustive list in perlsub, introduced as follows:

        Subroutines whose names are in all upper case are reserved to the Perl core, as are modules whose names are in all lower case. A subroutine in all capitals is a loosely-held convention meaning it will be called indirectly by the run-time system itself, usually due to a triggered event.... The following is a list of some subroutines that currently do special, pre-defined things.

        Note also:

        The BEGIN, UNITCHECK, CHECK, INIT and END subroutines are not so much subroutines as named special code blocks, of which you can have more than one in a package, and which you can not call explicitly.

        By contrast, AUTOLOAD is a (special) subroutine:

        13:43 >perl -MO=Deparse -we "AUTOLOAD { 'First' } AUTOLOAD { 'Second' +}" Subroutine AUTOLOAD redefined at -e line 1. BEGIN { $^W = 1; } sub AUTOLOAD { 'Second'; } -e syntax OK 13:43 >

        Hope that helps,

        Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,