in reply to Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.

Updated Preface:

I understand your question as the desire to use the same AUTOLOAD in different files/packages.

And I presume you already tried the obvious - importing - and it failed.

main

> *AUTOLOAD = \&BASE_CLASS::AUTOLOAD;  #this doesn't seem to work

one guess: did you put this in a BEGIN {} block?

untested since you didn't provide an SSCCE to reproduce it and the concept really looks like *a terrible hack*...

edit

A more terrible hack would be to do

BEGIN { eval <<"__CODE__"; sub AUTOLOAD { $BODY_OF_ORIG_AUTOLOAD } __CODE__ }

like this the AUTOLAD could be indistiguishible from a real autoload

edit

or

BEGIN { require "The_Autoload.pl"; }

with

sub AUTOLOAD { ... # Body of Autoload }

inside.

again untested for mentioned reasons

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.
by Anonymous Monk on Sep 27, 2021 at 15:03 UTC

    Hi, I have tried moving *AUTOLOAD = \&BASE_CLASS::AUTOLOAD; to BEGIN {} block, it's not working.
    Note that i am having perl 5.34.
    using require for that particular .pl file seems working for me, but i have to modify all such instances for the same.
    i am looking for better solution.
    Thank you

        Hi, my code looks below, please ignore previous comment

        ##script homepage.pl #this script has been located in cgi folder where + it also has SUBS/APP folder package homepage; our ($AUTOLOAD_DEFINED); # This isn't necessary, but without it you ge +t a warning when perl uses UNIVERSAL::AUTOLOAD if (!$AUTOLOAD_DEFINED) # (from lib.pl): "Use of inherited AUTOLOAD f +or non-method...". (search for that warning { # text in 'perldoc perldiag' for more info. *AUTOLOAD = \&APP::AUTOLOAD; $AUTOLOAD_DEFINED = 1; } # # #below is the non-method called from the perl file (getStatuses.pl) lo +cated at cgi/SUBS/APP/Statues @Statuses = &APP::Statuses::getStatuses({IsResolvedFlag =>1}); #here + is is failing to autoload the script getStatuses.pl.

        In other script (lib.pl) where AUTOLOAD function is defined which would control the autoloading part, it also has below line outside of AUTOLOAD function
        # use APP package's AUTOLOAD for all packages that don't have their ow +n *UNIVERSAL::AUTOLOAD = \&APP::AUTOLOAD;

        Note : I cant see anywhere autoLoader module has been used instead AUTOLOAD function has been written.
        I hope this helps you to understand the scenario.
        Thank you

      > but i have to modify all such instances for the same

      same with  *AUTOLOAD = \&BASE_CLASS::AUTOLOAD;

      (shrug) !

      I know many dirty workarounds° in Perl but I doubt what you want is possible or even desirable.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

      °) well as always with Perl ... provided the base class is directly used one could try a source filter to inject sub AUTOLOAD in the importing file. But I wanna be damned before showing how...

        FWIW: an even less stable hack would be to write something like an 'INIT {}' or 'CHECK{ }' block to indentify all defined packages/classes after compilation which inherit from the BASE_CLASS:: ( see ->isa in UNIVERSAL )

        all those packages could then have a new AUTOLOAD added via eval.

        this will not work in all cases because those timing issues in Perl are highly flexible:

        • a sub could have been called before compilation finished.
        • a class could be defined dynamically afterwards at runtime
        • ...

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery