With pluggable regexp engines a Regexp is actually a subclass of
Regexp, not Regexp itself.

(Another way to do this would be to use Scalar::Util::reftype and
check for REGEXP; however this only works since regexps became
a first class type in perl 5.12.)

I've not been able to run the tests, lots seem to be failing for me,
even before this change.
---
 lib/Moose/Util/TypeConstraints.pm                  |    2 +-
 .../Util/TypeConstraints/OptimizedConstraints.pm   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/Moose/Util/TypeConstraints.pm 
b/lib/Moose/Util/TypeConstraints.pm
index 1f66409..a7e3e12 100644
--- a/lib/Moose/Util/TypeConstraints.pm
+++ b/lib/Moose/Util/TypeConstraints.pm
@@ -731,7 +731,7 @@ subtype 'Int' => as 'Num' => where { "$_" =~ /^-?[0-9]+$/ } 
=>
 
 subtype 'CodeRef' => as 'Ref' => where { ref($_) eq 'CODE' } =>
     optimize_as \&Moose::Util::TypeConstraints::OptimizedConstraints::CodeRef;
-subtype 'RegexpRef' => as 'Ref' => where { ref($_) eq 'Regexp' } =>
+subtype 'RegexpRef' => as 'Ref' => where { blessed($_) && $_->isa('Regexp') } 
=>
     optimize_as
     \&Moose::Util::TypeConstraints::OptimizedConstraints::RegexpRef;
 subtype 'GlobRef' => as 'Ref' => where { ref($_) eq 'GLOB' } =>
diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm 
b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
index 5d54359..d1ba155 100644
--- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
+++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm
@@ -36,7 +36,7 @@ sub ScalarRef { ref($_[0]) eq 'SCALAR' || ref($_[0]) eq 'REF' 
}
 sub ArrayRef  { ref($_[0]) eq 'ARRAY'  }
 sub HashRef   { ref($_[0]) eq 'HASH'   }
 sub CodeRef   { ref($_[0]) eq 'CODE'   }
-sub RegexpRef { ref($_[0]) eq 'Regexp' }
+sub RegexpRef { blessed($_[0]) && $_[0]->isa('Regexp') }
 sub GlobRef   { ref($_[0]) eq 'GLOB'   }
 
 sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) or 
blessed($_[0]) && $_[0]->isa("IO::Handle") }
-- 
1.7.3.3

Reply via email to