develooper Front page | perl.perl5.porters | Postings from August 2001

Re: 'can' with undefined subs

Thread Previous | Thread Next
From:
Tony Bowden
Date:
August 25, 2001 12:07
Subject:
Re: 'can' with undefined subs
Message ID:
20010825151314.B11788@soto.kasei.com
On Fri, Aug 17, 2001 at 01:18:52AM +0100, Hugo van der Sanden wrote:
> :It also doesn't seem to be documented anywhere.
> 
> Patches welcome, as always. You may well find that we are deficient
> on tests for this behaviour as well. :)

Documentation patch:

-------

--- lib/UNIVERSAL.pm.11710      Sat Aug 25 15:00:31 2001
+++ lib/UNIVERSAL.pm    Sat Aug 25 15:13:49 2001
@@ -45,6 +45,15 @@
 then a reference to the sub is returned. If it does not then I<undef>
 is returned.

+C<can> cannot know whether an object will be able to provide a method
+through AUTOLOAD, so a return value of I<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 L<perlsub>)
+for methods they will handle via AUTOLOAD. For such 'dummy' subs, C<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.
+
 C<can> can be called as either a static or object method call.

 =item VERSION ( [ REQUIRE ] )

-------


Tony
-- 
--------------------------------------------------------------------------
 Tony Bowden | tony@tmtm.com | http://www.tmtm.com/
                                  And if you need my attention  Be bizarre
--------------------------------------------------------------------------

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