Adriano Ferreira a.r.ferreira at
Wed Jan 17 18:27:19 GMT 2007

On 1/17/07, ti at <ti at> wrote:
> UNIVERSAL::can tells you what methods are *in the hash*. It doesn't tell
> you what AUTOLOAD would do, because, as you say, it can't.

->can is a method. Its base implementation (the one provided by
UNIVERSAL package) "tells you what methods are *in the hash*" (as you
said). But ->can is a method and you may extend it as you feel
appropriate. If you what you feel appropriate is coherent, answering
the same as UNIVERSAL::can to the predefined methods and something
like \&AUTOLOAD to the other cases handled by AUTOLOAD, your ->can
will keep on with the abstraction of telling you what methods can
possibly be invoked over the object in question.

>This is because
> it can't predict the future, but also because the interfaces and
> conventions of Perl don't have anything to plug into AUTOLOAD which also
> sorts out "can". (Well, there are things that do that, like Class::Std,
> but they're not in very wide usage).

It is not about predicting the future. It is about complying with the
present written in your code. But nothing obliges you. You may write
an AUTOLOAD without a corresponding update to ->can and get away with
murder in a very large number of applications. But to be fully
consistent, there will be a time when the update to ->can will be
natural and felt as bug by your code users if it is missing.

More information about the mailing list