From: M.J.T. Guy Date: Mon, 24 Mar 1997 17:54:01 +0000 (+0000) Subject: Exporting UNIVERSAL::can X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a66bc3b0c7b47b1405c3f62393e8f35e9a4bbdb8;p=p5sagit%2Fp5-mst-13.2.git Exporting UNIVERSAL::can UNIVERSAL allows the export of 'isa' but not 'can'. Since it is useful to be able to apply 'can' to non-references (to avoid having to do redundant tests), I offer the following tiny patch. This also updates the pod to make it slightly clearer that both functions can be applied to arbitrary values, not just references. p5p-msgid: E0w9DwX-0000Zr-00@taurus.cus.cam.ac.uk --- diff --git a/lib/UNIVERSAL.pm b/lib/UNIVERSAL.pm index c0e7ebd..6d832c4 100644 --- a/lib/UNIVERSAL.pm +++ b/lib/UNIVERSAL.pm @@ -2,7 +2,7 @@ package UNIVERSAL; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(isa); +@EXPORT_OK = qw(isa can); 1; __END__ @@ -58,7 +58,7 @@ C also optionally exports the following subroutines =over 4 -=item isa ( REF, TYPE ) +=item isa ( VAL, TYPE ) C returns I if the first argument is a reference and either of the following statements is true. @@ -67,15 +67,22 @@ of the following statements is true. =item -C is a blessed reference and is blessed into package C +C is a blessed reference and is blessed into package C or inherits from package C =item -C is a reference to a C of perl variable (er 'HASH') +C is a reference to a C of perl variable (er 'HASH') =back +=item can ( VAL, METHOD ) + +If C is a blessed reference which has a method called C, +C returns a reference to the subroutine. If C is not +a blessed reference, or if it does not have a method C, +I is returned. + =back =cut