AUTOLOAD

chromatic chromatic at wgz.org
Sun Jan 14 23:45:44 GMT 2007


On Sunday 14 January 2007 15:01, Tim Sweetman wrote:

> chromatic says (I paraphrase) if you implement AUTOLOAD, but don't
> implement can, that's a bug, and you're lazy. (That might be a
> compliment, in this context, I'm unsure).

It's lazy in the sense that leaving the gas on may save you having to turn it 
on again ever, in the near future and in a permanent sense.

> The UNIVERSAL perldoc also says:
> >            "can" can be called as a class (static) method, an object
> > method, or a function.

Not the latest versions, which I patched to make them somewhat consistent with 
the idea that Perl programmers should be able to rely on somewhat minimum 
standards of correctness from their programs.

> And that's "use a forward declaration". NOT blame the "stupid"
> programmer for expecting UNIVERSAL::can($thing, "fly") to do what it
> means in English; NOT use Class::Std or UNIVERSAL::can to push the
> UNIVERSAL class's can implementation out of the way and do something
> different (and hopefully better).

That's not what the UNIVERSAL::can module does.

UNIVERSAL::can attempts to protect *working* code from breakage thanks to the 
buggy code of other people, warning copiously that invoking methods as 
functions has the nasty tendency to break working code.

> (OK, they agree on what happens, and how the Perl interpreter works, but
> as for what anyone's actually supposed to be doing, or what one can
> reasonably expect from a module author...?)

I suggest you immediately replace all of your constructors in your production 
code with Acme::UNIVERSAL::new for a very quick lesson on the value of 
adhering to superclass interfaces.  (If you don't use source control, 
consider it two lessons.)

It seems reasonable to me to expect people writing OO Perl to have some vague 
sense of how methods work.  Better yet if they actually *accept* that 
knowledge.

-- c



More information about the london.pm mailing list