Graham Barr wrote:
> 
> On Fri, Feb 21, 2003 at 04:34:42PM -0500, Dan Sugalski wrote:
> > If A isa B, we certainly wouldn't want to call A's AUTOLOAD on a
> > method before we looked to see if B had a concrete instance of that
> > method.
> 
> Right. The best you could probably do is note where you found the
> first AUTOLOAD so that when you do reach the end of the ISA search you
> don't need to do the whole search again.

Unless we changed the language in such a way that we could *tell*
whether or not we should try calling A's AUTOLOAD.

Currently, in perl5, if you have "package A; sub foo;", then the method
search will stop in A and call A's autoload, since it *knows* that A has
an appropriate method.

Obviously, we don't really want to force our users to stub every method
(though this would be *one* way of avoiding the need for a second pass
for AUTOLOADs)...  If the language had an AUTOPROTO/AUTOSTUB if some
sort, we could call it and find out where the heirarchy search should
stop in that class.

> But is this programming for the common case ? or is it premature
> optimization.

Well, first ask what are the common cases for autoloading in perl5...

I think that the *most* common case is AutoLoader/SelfLoader.

If Devel::SelfStubber is used with either of those, then that stops the
heirarchy search for methods in the right place, not needing a second
pass.

There are also definitions of XS constants ... though these are not, in
general, used as methods, so I suppose we can ignore them for now.

And finally, there are object property accessors, so that one can write
$c = $obj->color, instead of $c = $obj->{color}.  These are sometimes
done in AUTOLOAD... But stubs are rarely, if ever, provided for them, so
calling this type of method almost always requires two passes through
the inheritance heirarchy.

.....

There's also another case that's not-so-common, but mainly due to the
difficulties of doing it right in perl5.  You've suggested keeping track
of where we found the *first* AUTOLOAD ... but what happens if we want
to inherit from *two* classes with AUTOLOAD methods?  In perl5, you'd
have to use NEXT.pm, which, imho, is fairly ugly internally, and not
especially efficient (plus it's not in the core).  Perl6 should have a
built-in mechanism to allow an AUTOLOAD method to either make a call to
the next AUTOLOAD, a la NEXT.pm, (this might be fairly expensive), or
throw an exception saying that that particular method isn't supplied by
this AUTOLOAD, and have the search continue (possibly much less
expensive).

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print

Reply via email to