AUTOLOAD
Dirk Koopman
djk at tobit.co.uk
Wed Jan 17 13:45:24 GMT 2007
Simon Cozens wrote:
> Dirk Koopman:
>> Ok, I am willing to learn.
>
> You are making enough unsupported statements as it is, so I suspect that one
> is unsupported as well.
Something tells me that I am losing the plot here. Especially as there
is nothing in here, in terms of perl and its behaviour, that I disagree
with.
>
>> Could you please specify exactly what is wrong with the above statement?
>>> When messing with AUTOLOAD, the only thing that can() and its friends can
>>> tell you, reliably, about is any static method - such as
>>> $foo->can('AUTOLOAD').
>
>> Note the use of the word "reliably", which I choose to interpret as "at
>> *all* moments during the running of a program". The fact that (what I
>> choose to call) non-static methods can be created during the running of
>> a program, either through the use of AUTOLOAD or by other means, does
>> not equate to "reliable" in the context of the above statement + example.
>
> OK, your statement is wrong in at least three ways.
>
> First, there is no such thing as static and non-static methods. There are
> entries in a hash. That's all.
Thank you, I know that. But please read the words again. Sometimes my
english is not as expressive as I would, perhaps, like it to be, but
also people can be guilty of reading stuff into it that are not there.
>
> Second, ->can is reliable at all moments during the running of a program. It
> tells you what methods are available at the moment when you call it. It uses
> the same dispatch method that perl does, so it is guaranteed to be correct.
I absolutely and completely agree. However, if I draw you back to what I
understand was the original narrative: is it reasonable to mix can()
with AUTOLOAD and expect consistent results?
To which the answer is: it depends. Mainly on the programmers of all the
modules that are in use. Can() will not see as yet undefined methods
*unless* someone has arranged, in advance, for that to happen.
It is in that, narrow, sense that I use the word "reliably". It is *not*
perl here that is being potentially unreliable - it is the people that
write the stuff that I am accusing!
> If you want "reliability", though, you need to be intentional about
> your programming. Again, Perl should not be expected to reward stupidity. In
> most cases, you call ->can() on methods that you suspect might exist, and in
> most cases you have reason for such suspicions. And if you have a reason to
> suspect that a method might exist, you should also have some reasoning about
> how it might have been created. Entries in a hash table do not appear by
> magic. They're put there either at compile time or at run time.
Eloquently put. However, in these modern times we all use code put
together by third parties. Not all of this code is as well written, nor
is it documented sufficiently to enable a user to be able to use can()
"reliably" (or to do what he thinks he expects).
>
> I hate to break it to you, but magic data pixies don't exist.
>
I'm sorry, but I thought magic pixies (of all sorts) are in the charter
of L-PM, together with Buffy, Ponies and pie?
Dirk
More information about the london.pm
mailing list