summaryrefslogtreecommitdiff
path: root/lib/UNIVERSAL.pm
diff options
context:
space:
mode:
authorM.J.T. Guy <mjtg@cus.cam.ac.uk>1997-03-24 17:54:01 +0000
committerChip Salzenberg <chip@atlantic.net>1997-03-22 15:34:25 +1200
commita66bc3b0c7b47b1405c3f62393e8f35e9a4bbdb8 (patch)
tree974f77f3eca3a27195bbee3cd1ac1bdeafb62020 /lib/UNIVERSAL.pm
parent590feb52ba1fa31a38ae6316de4289419c5c6da0 (diff)
downloadperl-a66bc3b0c7b47b1405c3f62393e8f35e9a4bbdb8.tar.gz
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
Diffstat (limited to 'lib/UNIVERSAL.pm')
-rw-r--r--lib/UNIVERSAL.pm15
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/UNIVERSAL.pm b/lib/UNIVERSAL.pm
index c0e7ebdee2..6d832c4bea 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<UNIVERSAL> also optionally exports the following subroutines
=over 4
-=item isa ( REF, TYPE )
+=item isa ( VAL, TYPE )
C<isa> returns I<true> 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<REF> is a blessed reference and is blessed into package C<TYPE>
+C<VAL> is a blessed reference and is blessed into package C<TYPE>
or inherits from package C<TYPE>
=item
-C<REF> is a reference to a C<TYPE> of perl variable (er 'HASH')
+C<VAL> is a reference to a C<TYPE> of perl variable (er 'HASH')
=back
+=item can ( VAL, METHOD )
+
+If C<VAL> is a blessed reference which has a method called C<METHOD>,
+C<can> returns a reference to the subroutine. If C<VAL> is not
+a blessed reference, or if it does not have a method C<METHOD>,
+I<undef> is returned.
+
=back
=cut