diff options
author | Dan Book <grinnz@grinnz.com> | 2021-08-04 15:55:35 -0400 |
---|---|---|
committer | Paul Evans <leonerd@leonerd.org.uk> | 2021-08-22 14:53:30 +0100 |
commit | 38b5dc294ed4ebbdc84f167eb5766db6230bdbe6 (patch) | |
tree | 28c43a8b533020abe0e5256233a53096a8f01e06 | |
parent | 213dc9d1dd41762afd38cca1e663ed29a5cedca8 (diff) | |
download | perl-38b5dc294ed4ebbdc84f167eb5766db6230bdbe6.tar.gz |
perlfunc 'ref' and UNIVERSAL: document isa operator alternative
-rw-r--r-- | lib/UNIVERSAL.pm | 7 | ||||
-rw-r--r-- | pod/perlfunc.pod | 4 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/UNIVERSAL.pm b/lib/UNIVERSAL.pm index 12800fb54c..e73c988aba 100644 --- a/lib/UNIVERSAL.pm +++ b/lib/UNIVERSAL.pm @@ -1,6 +1,6 @@ package UNIVERSAL; -our $VERSION = '1.13'; +our $VERSION = '1.14'; # UNIVERSAL should not contain any extra subs/methods beyond those # that it exists to define. The existence of import() below is a historical @@ -87,7 +87,10 @@ inherits from (or is itself) the name of the package C<TYPE> or inherits from package C<TYPE>. If you're not sure what you have (the C<VAL> case), wrap the method call in an -C<eval> block to catch the exception if C<VAL> is undefined. +C<eval> block to catch the exception if C<VAL> is undefined or an unblessed +reference. The L<C<isa> operator|perlop/"Class Instance Operator"> is an +alternative that simply returns false in this case, so the C<eval> is not +needed. If you want to be sure that you're calling C<isa> as a method, not a class, check the invocand with C<blessed> from L<Scalar::Util> first: diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 8227969f4f..6ae2ea1222 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -6578,7 +6578,9 @@ L<C<Scalar::Util::blessed()>|Scalar::Util/blessed> for information about blessing, and L<C<Scalar::Util::reftype()>|Scalar::Util/reftype> for information about physical types. Use L<the C<isa> method|UNIVERSAL/C<< $obj->isa( TYPE ) >>> for class membership tests, though one must be -sure of blessedness before attempting a method call. +sure of blessedness before attempting a method call. Alternatively, the +L<C<isa> operator|perlop/"Class Instance Operator"> can test class +membership without checking blessedness first. See also L<perlref> and L<perlobj>. |