simon at simon-cozens.org
Wed Jan 17 12:53:53 GMT 2007
> Ok, I am willing to learn.
You are making enough unsupported statements as it is, so I suspect that one
is unsupported as well.
> 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
> 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.
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. If
you have any instances of ->can giving untruthful answers, please file a bug
in perl. The only way I can imagine of your statement being true would be if
you willingly take the result of ->can, file it away somewhere, call a bunch
of random methods which may or may not create some new methods, then assume
that the result of the earlier ->can is still valid. But this is a stupid
thing to do, and Perl should not be expected to reward programmers for their
stupidity. AUTOLOAD is irrelevant to that point.
Third, I'm presuming that you're calling ->can intentionally. That is, that
you chose to write the method call into a program, and you knew what you were
doing. I recognise these are pretty dodgy assumptions. If you knew what you
were doing, you passed it a sensible parameter, rather than some random
string. If you passed it a random string, you should expect to get random
results. 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. They're put
there by code. Your code. You should know what your code does.
If you do not know what your code does, the answer you get from ->can() won't
be able to help you anyway.
Your argument seems to be "if magic data pixies created a bunch of methods,
then I can't reliably tell what my code is doing." This is a correct
statement, but based on an incorrect assumption.
I hate to break it to you, but magic data pixies don't exist.
If you don't know where you are going, any road will get you there.
More information about the london.pm