develooper Front page | perl.perl5.porters | Postings from January 2000

Re: On Pseudohashes

Thread Previous | Thread Next
Tim Bunce
January 17, 2000 06:53
Re: On Pseudohashes
Message ID:
On Mon, Jan 17, 2000 at 07:08:52AM -0700, Tom Christiansen wrote:
> >It's always been advisable for classes to pre-declare all their methods
> >if using AUTOLOAD.
> Tim, some time ago something came up about autoloading method calls
> that bothered me in an MI scenario.  Seems to me you respondedi
> similarly then.  I'm pretty sure it was the following inheritance
> scenario:
>                 A
>                  \
>                   B   C         @B::ISA = ('A');
>                    \ /
>                     D           @D::ISA = ('B', 'C');
> Suppose that each of those classes were using autoloading to generate
> its attribute accessors.  If D->m() is called, and that method m()
> is really supposed to be handled iby C, there's no way for B's
> autoload to "super" it over to C.  Instead, B::SUPER just gets to
> ascend to A--which doesn't help.  You can never renege on an AUTOLOAD
> so that Perl's method lookup would treat that hit as a miss and
> then go on to inspect sibling branches of the tree.
> Does pre-declaring methods to be handled via AUTOLOAD entirely clear
> this matter up?

I believe so.  Here's my simplistic understanding:

  First perl will search the whole inheritance tree looking for a
  declared method of the required name, but _ignoring_ AUTOLOAD.
  A simple "sub foo;" predeclaration will suffice to match.

  If it doesn't find the method it will then repeat the search, only
  this time it'll be trying to find an AUTOLOAD which it'll then invoke.

What's needed, if you don't want to pre-declare all the methods, is
some way for autoload to say it 'failed'. I see it in the Todo-5.005
file as "_AUTOLOAD prodding" (in perl5.005_63).

> If there some obvious advantage to using AUTOLOAD
> over, say, iterated registration of closures in the package symbol
> table?

No idea. I've not thought about it.

> In my libertine youth, I would frequently advocate AUTOLOAD
> to cover generic accessor methods, but in later years I've grown
> to mistrust in the extreme that particular strategy for realistically
> complex class hierarchies.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About