On 31 Dec 2010, at 18:41, Florian Ragwitz wrote:
> The specialness of regexp refs mostly comes from either having an SV
> type of SVt_REGEXP on new perls, or from PERL_MAGIC_qr on older perls.

That's what I was getting at with my reftype comment, I've just realised 
re::is_regexp exists which is probably the 'right' way of doing this, except 
this doesn't exist before perl 5.10 by the look of it :(

So maybe it needs a bit of XS code that calls SvRXOK to support 5.8 (or just 
use ->isa('Regexp') on 5.8?)

> They also happen to be blessed into a class called `Regexp' by default
> and can be blessed into any package explicitly, but that doesn't
> actually influence how they behave as a regexp.
> 
> Given that, I'd expect the RegexpRef type constraint to only accept
> things that are actually references to regexps - i.e. something of type
> SVt_REGEXP or with proper qr magic, not any reference blessed into the
> class `Regexp' or any of its subclasses.
> 
> That will accept both regular regexp refs and regexp refs using re
> plugins.

That makes sense to me.

> If someone wants to be less strict, which I'm not sure the point of
> would be, he should probably use a regular class type instead:
> 
>  isa => 'Regexp'
> 
> 
> Note that this might be a slightly backward-incompatible
> change. Currently the Object type constraint explicitly excludes things
> blessed into `Regexp', even if the reference points to, say, a hash.
> 
> Also the RegexpRef constraint currently accepts any kind of blessed
> reference, not only blessed references to regexps. That'd have to change
> as well.
> 
> The amount of code this change would break does seem minimal to me.

Yes, I find it confusing that the Object type excludes just 'Regexp' -- it 
would be good to fix this as it means this is inconsistent with subclassed 
Regexps too.

David

Reply via email to