Skip Menu |

This queue is for tickets about the Params-Classify CPAN distribution.

Report information
The Basics
Id: 86282
Status: rejected
Priority: 0/
Queue: Params-Classify

People
Owner: Nobody in particular
Requestors: KENTNL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in: 0.013
Fixed in: (no value)



Subject: check_regexp can't detect regexp

use strict;
use warnings;
use utf8;
use Test::More;
use Test::Fatal;
use Params::Classify;

is(exception {    Params::Classify::check_regexp(qr/asf/) }, 'undef', 'direct regexps are regexps' );
my $v = qr/asf/;
is(exception {    Params::Classify::check_regexp($v) }, 'undef', 'valued regexps are regexps' );
done_testing;

 

^ both these tests fail.

Actually, not sure why I quoted undef, but unquoting it doesn't fix the problem either, XD

 

not ok 1 - direct regexps are regexps
#   Failed test 'direct regexps are regexps'
#   at /tmp/e.pl line 28.
#          got: 'argument is not a regexp
# '
#     expected: undef
not ok 2 - valued regexps are regexps
#   Failed test 'valued regexps are regexps'
#   at /tmp/e.pl line 30.
#          got: 'argument is not a regexp
# '
#     expected: undef
not ok 3 - valued regexps are regexps
#   Failed test 'valued regexps are regexps'
#   at /tmp/e.pl line 32.
#          got: 'argument is not a regexp
# '
#     expected: undef
1..3
# Looks like you failed 3 tests of 3


> not ok 3 - valued regexps are regexps
> # Failed test 'valued regexps are regexps'
> # at /tmp/e.pl line 32.
> # got: 'argument is not a regexp
> # '

^ and that is just

is(exception {    Params::Classify::check_regexp(\$v) }, undef, 'valued regexps are regexps' );

 

Because I wanted to make sure it wasn't getting weird.

Subject: Re: [rt.cpan.org #86282] check_regexp can't detect regexp
Date: Thu, 20 Jun 2013 18:05:25 +0100
To: Kent Fredric via RT <bug-Params-Classify [...] rt.cpan.org>
From: Zefram <zefram [...] fysh.org>
Kent Fredric via RT wrote: Show quoted text
>is(exception { Params::Classify::check_regexp(qr/asf/) }, 'undef', 'direct >regexps are regexps' );
qr/asf/ isn't a regexp, it's a *reference to* a regexp. Try ${qr/asf/}. -zefram
On 2013-06-21 05:05:50, zefram@fysh.org wrote:
Show quoted text
> Kent Fredric via RT wrote:
> >is(exception { Params::Classify::check_regexp(qr/asf/) }, 'undef', 'direct
> >regexps are regexps' );
>
> qr/asf/ isn't a regexp, it's a *reference to* a regexp. Try ${qr/asf/}.
>
> -zefram

Ah!. That helps muchly.  I guess I misunderstood the check. I didn't even realise you could dereference a regexp-ref .

Could you be persuaded to add a little documentation clarifying the distinction ?  =)

And to clarify, how is this behaviour considered "useful"? There doesn't appear to be any way to create a regexp ref other than the qr// construct.

Making everyone dereference prior to calling "is a regexp" seems just prone to cause confusion.

Subject: Re: [rt.cpan.org #86282] check_regexp can't detect regexp
Date: Fri, 21 Jun 2013 11:15:23 +0100
To: Kent Fredric via RT <bug-Params-Classify [...] rt.cpan.org>
From: Zefram <zefram [...] fysh.org>
Kent Fredric via RT wrote: Show quoted text
>Could you be persuaded to add a little documentation clarifying the distinction >? =)
I'm open to suggestions as to how to clarify it. I thought it was clear enough already. Show quoted text
>And to clarify, how is this behaviour considered "useful"?
On the module side, it's part of a consistent pattern, that each kind of scalar has a test of the same form. In the core, regexps are now a distinct type mainly for transparency: previously a regexp appeared as undef, with the actual information hidden in attached magic. Show quoted text
>Making everyone dereference prior to calling "is a regexp" seems just prone to >cause confusion.
You'll hardly ever want to check against the REGEXP type. Regexp objects are normally blessed into the "Regexp" package. (They've been so blessed as long as qr// has existed; the blessing was applied in the days of undef-with-magic, before the REGEXP type existed.) You'll want check_blessed($v, "Regexp") instead. -zefram