Skip Menu |

This queue is for tickets about the Scalar-List-Utils CPAN distribution.

Report information
The Basics
Id: 127963
Status: resolved
Priority: 0/
Queue: Scalar-List-Utils

People
Owner: Nobody in particular
Requestors: rkleemann [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.54



Subject: reftype on Regexp doesn't behave as expected
Date: Fri, 7 Dec 2018 14:40:37 -0800
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Bob Kleemann <rkleemann [...] gmail.com>
The output of "perl -MScalar::Util=reftype -E 'say reftype(qr/abc/)'" does not return the same value as "perl -E 'say ref(qr/abc/)'"? Specifically, the first returns the all-capitals REGEXP, whereas the latter returns the mixed-case Regexp. I would expect that the return values for reftype would either match those as documented for ref, or that the documentation would note the differences.
On Fri Dec 07 17:41:06 2018, rkleemann@gmail.com wrote: Show quoted text
> The output of "perl -MScalar::Util=reftype -E 'say reftype(qr/abc/)'" does > not return the same value as "perl -E 'say ref(qr/abc/)'"? Specifically, > the first returns the all-capitals REGEXP, whereas the latter returns the > mixed-case Regexp. I would expect that the return values for reftype would > either match those as documented for ref, or that the documentation would > note the differences.
The values returned by qr// are REGEXP references blessed into the Regexp package. ref returns a different value than reftype for these, just like any other object.
Subject: Re: [rt.cpan.org #127963] reftype on Regexp doesn't behave as expected
Date: Mon, 10 Dec 2018 11:29:13 -0800
To: bug-Scalar-List-Utils [...] rt.cpan.org
From: Bob Kleemann <rkleemann [...] gmail.com>
I wasn't aware that qr// returned a blessed reference, rather than just a reference. It's not obvious from any of the documentation that I've read (Scalar::Utils, perlop, and perlfunc, among others) that the difference is between the underlying structure and the pseudo-class (perldoc doesn't seem to know about the Regexp package/class). Please update the documentation to note the single, unexpected difference from ref: Note: reftype(qr/abc/) differs from the ref(qr/abc/). The former returns the name of the underlying structure, in all capitals: "REGEXP"; while the latter returns the name of the pseudo-class in mixed case: "Regexp". On Sun, Dec 9, 2018 at 3:18 AM Graham Knop via RT < bug-Scalar-List-Utils@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=127963 > > > On Fri Dec 07 17:41:06 2018, rkleemann@gmail.com wrote:
> > The output of "perl -MScalar::Util=reftype -E 'say reftype(qr/abc/)'"
> does
> > not return the same value as "perl -E 'say ref(qr/abc/)'"? Specifically, > > the first returns the all-capitals REGEXP, whereas the latter returns the > > mixed-case Regexp. I would expect that the return values for reftype
> would
> > either match those as documented for ref, or that the documentation would > > note the differences.
> > The values returned by qr// are REGEXP references blessed into the Regexp > package. ref returns a different value than reftype for these, just like > any other object. >
Added some words to the docs: -- Paul Evans
Subject: rt127963.patch
commit f1f94dcdb6179a1fc35d9d934b8d59d896325168 Author: Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> Date: Wed Jan 29 14:29:36 2020 +0000 Document the subtle difference between ref(qr//) and reftype(qr//) (RT127963) diff --git a/lib/Scalar/Util.pm b/lib/Scalar/Util.pm index bf670c9..f123b68 100644 --- a/lib/Scalar/Util.pm +++ b/lib/Scalar/Util.pm @@ -134,6 +134,11 @@ is returned. $obj = bless {}, "Foo"; $type = reftype $obj; # HASH +Note that for internal reasons, all precompiled regexps (C<qr/.../>) are +blessed references; thus C<ref()> returns the package name string C<"Regexp"> +on these but C<reftype()> will return the underlying C structure type of +C<"REGEXP"> in all capitals. + =head2 weaken weaken( $ref );
This is now on CPAN as part of 1.54 -- Paul Evans