Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^6: Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.

by Anonymous Monk
on Sep 28, 2021 at 18:07 UTC ( #11137093=note: print w/replies, xml ) Need Help??


in reply to Re^5: Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.
in thread Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.

Below is the code to reproduce the error.

package Homepage; use strict; use warnings; use diagnostics; require "MRlib.pl"; #this script has logic for AUTOLOAD written, wher +e it checks for main package and method name and call for require<br/ +> ## Upon using below require it works, otherwise, it throws Use of inhe +rited AUTOLOAD for non-method FP::Introduction::Introduce() is no lon +ger allowed at test_autoload.pl line 17. error ## require "C:\\Users\\xxx\\Documents\\Application\\Perl_upgrade\\test +_autoload\\SUBS\\App\\Introduction.pl"; BEGIN { *AUTOLOAD = \&FP::AUTOLOAD; } print "I started the program\n"; #Below Introduce sub is written in "C:\\Users\\xxx\\Documents\\Applica +tion\\Perl_upgrade\\test_autoload\\SUBS\\App\\Introduction.pl" script &FP::Introduction::Introduce; print "I got to the end of the program\n"; 1;


I hope it makes sense now !
Thank you

  • Comment on Re^6: Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.
  • Download Code

Replies are listed 'Best First'.
Re^7: Use of inherited AUTOLOAD for non-method is no longer allowed with Perl 5.34.
by tybalt89 (Prior) on Sep 28, 2021 at 22:55 UTC

    Try changing

    *AUTOLOAD = \&FP::AUTOLOAD;
    to
    *FP::Introduction::AUTOLOAD = \&FP::AUTOLOAD;
    so that it matches the call you are making;

      Yes. This could explain the issue
      • first version had &UNIVERSAL::AUTOLOAD defined which started to cause warnings after deprication
      • someone started to add *AUTOLOAD=\&MASTER::AUTOLOAD and got rid of most but not all warnings, because he missed some packages.
      • the missed packages which still relied on UNIVERSAL fail now.
      consequence
      • The &UNIVERSAL::AUTOLOAD is cargo cult now and should be deleted°
      • The missed packages must be "repaired"
      (untested, till someone provides a real SSCCE)

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

      °) also because it's a horrible idea causing many problems

        > (untested, till someone provides a real SSCCE)

        here we go to prove my theory

        this works (in a wider sense ;):

        use strict; use warnings; # https://perlmonks.org/?node_id=11137026 package Base; use Data::Dumper; sub AUTOLOAD { our $AUTOLOAD; warn "$AUTOLOAD => ", Dumper \@_; } #*UNIVERSAL::AUTOLOAD = \&AUTOLOAD; package Bla; *AUTOLOAD = \&Base::AUTOLOAD; # aka Bla::AUTOLOAD some_sub(1,2,3); *Foo::AUTOLOAD = \&Base::AUTOLOAD; Foo::some_sub(4,5,6)

        -*- mode: compilation; default-directory: "d:/tmp/pm/" -*- Compilation started at Wed Sep 29 12:33:29 C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/universal_autoload.pl Name "Foo::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer +sal_autoload.pl line 25. Name "Bla::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer +sal_autoload.pl line 19. Bla::some_sub => $VAR1 = [ 1, 2, 3 ]; Foo::some_sub => $VAR1 = [ 4, 5, 6 ]; Compilation finished at Wed Sep 29 12:33:29

        this horribly fails (please note also all those potential problems caused by UNIVERSAL::AUTOLOAD by triggering with intentionally undefined methods)

        use strict; use warnings; # https://perlmonks.org/?node_id=11137026 package Base; use Data::Dumper; sub AUTOLOAD { our $AUTOLOAD; return if $AUTOLOAD =~ /::DESTROY$/; # ignore destruction * warn "$AUTOLOAD => ", Dumper \@_; } *UNIVERSAL::AUTOLOAD = \&AUTOLOAD; package Bla; *AUTOLOAD = \&Base::AUTOLOAD; # aka Bla::AUTOLOAD some_sub(1,2,3); #*Foo::AUTOLOAD = \&Base::AUTOLOAD; Foo::some_sub(4,5,6)

        -*- mode: compilation; default-directory: "d:/tmp/pm/" -*- Compilation started at Wed Sep 29 12:37:45 C:/Strawberry/perl/bin\perl.exe -w d:/tmp/pm/universal_autoload.pl Name "UNIVERSAL::AUTOLOAD" used only once: possible typo at d:/tmp/pm/ +universal_autoload.pl line 15. Name "Bla::AUTOLOAD" used only once: possible typo at d:/tmp/pm/univer +sal_autoload.pl line 20. Bla::some_sub => $VAR1 = [ 1, 2, 3 ]; Use of inherited AUTOLOAD for non-method Foo::some_sub() is no longer +allowed at d:/tmp/pm/universal_autoload.pl line 28. Compilation exited abnormally with code 255 at Wed Sep 29 12:37:45

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

        update

        *) added, otherwise the output is littered with all objects with undefined DESTROY methods triggering AUTOLOAD.

      Hi, Thank you for the suggestion , while it seems to work for the FP package, it is failing with below error for other packages in the code like MRhomepage.
      MRhomepage::MRhomepage__getHomepageType() is no longer allowed.
      Is there any way to make it more generic?
      Thank you

        I'm guessing your file "MRlib.pl" has a mapping from package name to file to require.
        Use that package name list to generate and eval a set of *${packagename}::AUTOLOAD = \&FP::AUTOLOAD; statements.
        That may have to be in a BEGIN block.

        UPDATE: fixed ')' to '}'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2021-11-27 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?