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
From:
Chris Prather
Date:
October 29, 2007 20:32
Subject:
Re: [perl #46987] OO-call failures, autoviv-functions & testing their existence
Message ID:
918E57B7-D41F-4A18-9602-7C1BA9EF934E@prather.org

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.


from http://search.cpan.org/~nwclark/perl-5.8.8/lib/UNIVERSAL.pm

-Chris

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About