AUTOLOAD and can

TorgoX on 2002-02-24T18:47:30

Dear Log,

Thought for the day: if you provide an AUTOLOAD for a class, you should also provide a can, so that you will avoid the situation of $object->can('hoozits') returning false where 'hoozits' is an autoloaded method.


Indeed

pudge on 2002-02-24T22:04:17

In Mac::Glue, which has a somewhat elborate AUTOLOAD system (methods are created on the fly based on information in one or more glue files) I told can() to call AUTOLOAD() in such a way that AUTOLOAD() knows what to do: it goes through the same motions, but once creating the method, instead of executing it, it is merely caches as normal and then a reference is returned.

Re:Indeed

TorgoX on 2002-02-24T23:13:42

Excellent! Just what I was thinking!

Either that, or put the actual make-the-routine stuff in can(), and have AUTOLOAD just call the can() to make return the routine (if can), and then just put that into the symbol table and move on. Too bad this isn't in any of examples of AUTOLOAD use that I've seen.

Re:Indeed

pudge on 2002-02-24T23:26:38

That's a good thought; perhaps if I had thought of can() when I first did AUTOLOAD(), I might have done it that way. It'd be just as easy, and probably even cleaner. But can() is usually an afterthought at best. Maybe someday when I feel like just playing with it, I'll rewrite it to do that.