Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

TorgoX (1933)

TorgoX
  sburkeNO@SPAMcpan.org
http://search.cpan.org/~sburke/

"Il est beau comme la retractilité des serres des oiseaux rapaces [...] et surtout, comme la rencontre fortuite sur une table de dissection d'une machine à coudre et d'un parapluie !" -- Lautréamont

Journal of TorgoX (1933)

Sunday February 24, 2002
01:47 PM

AUTOLOAD and can

[ #3090 ]
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.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Indeed (Score:2, Informative)

    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.
    • 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.

      • 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.