develooper Front page | perl.perl5.porters | Postings from October 2007

Re: [perl #46987] OO-call failures, autoviv-functions & testing their existence

Thread Previous | Thread Next
Chris Prather
October 29, 2007 20:32
Re: [perl #46987] OO-call failures, autoviv-functions & testing their existence
Message ID:

On Oct 29, 2007, at 9:37 p, Linda W wrote:

> A second problem is that the UNIVERSAL "can()" method is broken
> as well.  According to OO-Perl(Conway), "can only returnes true if an
> object or class can call the method requested".  If the local method
> is "undefined" (as is stated in the error message), then "can()"
> cannot return a reference to that function -- since that function  
> method
> is NOT legally callable.

This actually is documented behavior:

can cannot know whether an object will be able to provide a method
through AUTOLOAD, so a return value of undef does not necessarily
mean the object will not be able to handle the method call. To get
around this some module authors use a forward declaration (see perlsub)
for methods they will handle via AUTOLOAD. For such 'dummy' subs, can
will still return a code reference, which, when called, will fall
through to the AUTOLOAD. If no suitable AUTOLOAD is provided, calling
the coderef will cause an error.



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About