Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Agreed, but I say playing nicely is a practice that does not scale. If you won't distribute the code there is nothing wrong with using AUTOLOAD.

I am saying that AUTOLOAD does not scale well. Every use of AUTOLOAD in a program should be under the control of one party. If two separate authors use AUTOLOAD in the same program breakage is likely.

Being conservative, I would be suspicious of any program with more than one AUTOLOAD. If two AUTOLOAD routines exist in a hierarchy there is a problem. (Don't forget UNIVERSAL.)

This is a known problem. Consider:

#!/usr/bin/perl use strict; use warnings; # I decide to use a module package Vehicle; use vars '$AUTOLOAD'; sub new { return bless {}, $_[0]; } # handle all "V*" calls sub AUTOLOAD { my ($key) = $AUTOLOAD =~/::(\w+)/; return if $key =~ /^[A-Z]+$/; die "Vehicle::AUTOLOAD can't cope as $key" unless $key =~ /^[vV]/; print "Leaving Vehicle::AUTOLOAD as $key$/"; } # with my program below package Animal; use vars '$AUTOLOAD'; sub new { return bless {}, $_[0]; } # handle all "A*" calls sub AUTOLOAD { my ($key) = $AUTOLOAD =~/::(\w+)/; return if $key =~ /^[A-Z]+$/; die "Animal::AUTOLOAD can't cope as $key" unless $key =~ /^[aA]/; print "Leaving Animal::AUTOLOAD as $key$/"; } package Horse; use vars qw/ @ISA /; @ISA = qw/ Vehicle Animal /; package main; # the two usages cannot work together, I needed to # know that Vehicle used AUTOLOAD so I could avoid it # or rewrite my code to eliminate AUTOLOAD. my $h = Horse->new; $h->Veh(); $h->Ani(); # call intercepted by Vehicle AUTOLOAD
Be well.

In reply to Re: Re: AUTOLOAD does not scale by rir
in thread OO Inheritence by Limbic~Region

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others pondering the Monastery: (5)
    As of 2018-01-19 18:29 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (222 votes). Check out past polls.