In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/2e06b51cf21f0d70a782e77099e579ac30d69d3b?hp=fab3d10781b2a5e8067e1e72de1f16af573fe356>
- Log ----------------------------------------------------------------- commit 2e06b51cf21f0d70a782e77099e579ac30d69d3b Merge: fab3d10 2496858 Author: Tony Cook <[email protected]> Date: Mon Jul 29 14:24:58 2013 +1000 [perl #114964] Correct 'ref' func POD to fix bad behavior around 'class matching' commit 24968583d9530f97b9c4197ebf26064f9beeeffc Author: Tony Cook <[email protected]> Date: Mon Jul 29 14:23:07 2013 +1000 mention reftype too M pod/perlfunc.pod commit 1016e6c3dc1f8ce518e58323c307b9f79aaef236 Author: Tony Cook <[email protected]> Date: Mon Jul 29 14:09:58 2013 +1000 Brendan Byrd is now a perl AUTHOR M AUTHORS commit 0373590a42c46727c94b3936832901d39e0d97c1 Author: Brendan Byrd <[email protected]> Date: Wed Sep 19 10:32:40 2012 -0400 Correct 'ref' func POD to fix bad behavior around "class matching" M pod/perlfunc.pod ----------------------------------------------------------------------- Summary of changes: AUTHORS | 1 + pod/perlfunc.pod | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index b5adf21..629b456 100644 --- a/AUTHORS +++ b/AUTHORS @@ -153,6 +153,7 @@ Brad Hughes <[email protected]> Brad Lanam <[email protected]> Bradley Dean <[email protected]> Bram <[email protected]> +Brendan Byrd <[email protected]> Brendan O'Dea <[email protected]> Brent B. Powers <[email protected]> Breno G. de Oliveira <[email protected]> diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 129012c..4de31ac 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -5680,9 +5680,9 @@ X<ref> X<reference> =for Pod::Functions find out the type of thing being referenced Returns a non-empty string if EXPR is a reference, the empty -string otherwise. If EXPR -is not specified, C<$_> will be used. The value returned depends on the -type of thing the reference is a reference to. +string otherwise. If EXPR is not specified, C<$_> will be used. The +value returned depends on the type of thing the reference is a reference to. + Builtin types include: SCALAR @@ -5697,8 +5697,7 @@ Builtin types include: VSTRING Regexp -If the referenced object has been blessed into a package, then that package -name is returned instead. You can think of C<ref> as a C<typeof> operator. +You can think of C<ref> as a C<typeof> operator. if (ref($r) eq "HASH") { print "r is a reference to a hash.\n"; @@ -5715,6 +5714,17 @@ to a L<version string|perldata/"Version Strings">. The result C<Regexp> indicates that the argument is a regular expression resulting from C<qr//>. +If the referenced object has been blessed into a package, then that package +name is returned instead. But don't use that, as it's now considered +"bad practice". For one reason, an object could be using a class called +C<Regexp> or C<IO>, or even C<HASH>. Also, C<ref> doesn't take into account +subclasses, like C<isa> does. + +Instead, use C<blessed> (in the L<Scalar::Util> module) for boolean +checks, C<isa> for specific class checks and C<reftype> (also from +L<Scalar::Util>) for type checks. (See L<perlobj> for details and a +C<blessed/isa> example.) + See also L<perlref>. =item rename OLDNAME,NEWNAME -- Perl5 Master Repository
