AUTOLOAD is failing to get called for sub calls of the form Xxxx->new when the class Xxxx has never been seen before.
Calls of Xxxx::new invoke AUTOLOAD correctly.

I have an example where having a LATER line in the code of the form: Xxxx::foobar makes AUTOLOAD trigger correctly for the prior line of Xxxx->new. Commenting out this line makes the earlier line fail. This seems bizarre behavour. Does this mean something is occuring at compile time?

This behavour occurs on perl 5.8.0 on IRIX and Linux platforms but does not occur on perl 5.6.1 on Win32 and Linux platforms or perl 5.005_03 on IRIX and Win32 platforms

This is creating a big problem for us as we have hundreds of calls of this form most of which rely on AUTOLOAD to load the class and method(s) on demand to keep the memory footprint down.

Here is an example that demonstrates the problem, note the lines to be uncommented near the bottom:

#!/usr/local/bin/perl -w package UNIVERSAL; sub AUTOLOAD { print "UNIVERSAL::AUTOLOAD=$AUTOLOAD\n" unless $AUTOLOAD =~ /DEST +ROY/; if ($AUTOLOAD =~ /^(.*)::(.*)$/ ) { my ($class,$sub) = ($1,$2); if ($sub eq 'new') { my $self = {xxx => 1}; bless $self, $class; return $self; } else { return "$AUTOLOAD **results**"; } } } #test forms of AUTOLOAD package main; my $n; #the following succeeeds but gets message: # Use of inherited AUTOLOAD for non-method foo::anysub() # is deprecated... my $xx=foo::anysub(); print ref $xx ? "object class:$xx\n" : "sub:$xx\n"; #the following succeeeds and returns an object of class foo my $xx=foo->new(); print ref $xx ? "object class:$xx\n" : "sub:$xx\n"; # *** IF THE LINES FURTHER ON ARE COMMENTED THIS FAILS WITH MESSAGE: # Can't locate object method "new" via package "bar" (perhaps # you forgot to load "bar"?)... # *** OTHERWISE IT WORKS WHY?? *** my $xx=bar->new(); print ref $xx ? "object class:$xx\n" : "sub:$xx\n"; # *** IF YOU UNCOMMENT THESE 2 LINES THE ABOVE WORKS *** #my $xx=bar::new(); #print ref $xx ? "object class:$xx\n" : "sub:$xx\n"; print "Finished\n";
Thanks,
Graham

In reply to AUTOLOAD fails in perl 5.8.0 by Graham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.