clean up duck type a bunch
Jesse Luehrs [Mon, 29 Aug 2011 17:33:35 +0000 (12:33 -0500)]
Conflicts:

Changes

Changes
lib/Moose/Meta/TypeConstraint/DuckType.pm

diff --git a/Changes b/Changes
index 8668613..ec4f1a0 100644 (file)
--- a/Changes
+++ b/Changes
@@ -9,6 +9,9 @@ for, noteworthy changes.
     -alias or -excludes caused a warning. However, passing other options is
     totally valid when using MooseX::Role::Parameterized. (sartak)
 
+  * Allow regexp objects in duck_type constraints (to bring this in line with
+    the Object constraint)
+
 2.0204 Thu, Aug 25, 2011
 
   [BUG FIXES]
index 09f0b86..02c12d0 100644 (file)
@@ -22,12 +22,14 @@ my $inliner = sub {
     my $self = shift;
     my $val  = shift;
 
-    return 'my $val = ' . $val . '; Scalar::Util::blessed($val) '
-             . '&& Scalar::Util::blessed($val) ne "Regexp" '
-             . '&& &List::MoreUtils::all('
-                 . 'sub { $val->can($_) }, '
+    return $self->parent->_inline_check($val)
+         . ' && do {' . "\n"
+             . 'my $val = ' . $val . ';' . "\n"
+             . '&List::MoreUtils::all(' . "\n"
+                 . 'sub { $val->can($_) },' . "\n"
                  . join(', ', map { B::perlstring($_) } @{ $self->methods })
-             . ')';
+             . ');' . "\n"
+         . '}';
 };
 
 sub new {
@@ -39,8 +41,7 @@ sub new {
     my @methods = @{ $args{methods} };
     $args{constraint} = sub {
         my $val = $_[0];
-        blessed($val) && blessed($val) ne 'Regexp'
-            && all { $val->can($_) } @methods;
+        return all { $val->can($_) } @methods;
     };
 
     $args{inlined} = $inliner;
@@ -75,17 +76,6 @@ sub equals {
     return 1;
 }
 
-sub constraint {
-    my $self = shift;
-
-    my @methods = @{ $self->methods };
-
-    return sub {
-        my $obj = shift;
-        return all { $obj->can($_) } @methods
-    };
-}
-
 sub create_child_type {
     my ($self, @args) = @_;
     return Moose::Meta::TypeConstraint->new(@args, parent => $self);