test the type constraint directly, don't be clever
[gitmo/MooseX-Types.git] / lib / MooseX / Types / TypeDecorator.pm
index fa97bb7..943bcd6 100644 (file)
@@ -117,8 +117,10 @@ handle $self->isa since AUTOLOAD can't.
 =cut
 
 sub isa {
-  return 1 if $_[1]->isa('Moose::Meta::TypeConstraint');
-  shift->_try_delegate('isa', @_)
+  my $self = shift;
+  return
+    $self->__type_constraint->isa(@_)
+    || $self->_try_delegate('isa', @_);
 }
 
 =head2 can
@@ -173,13 +175,16 @@ sub _try_delegate {
     my ($self, $method, @args) = @_;
     my $tc = $self->__type_constraint;
     my $class;
-    my $search_tc = $tc;
-    while ($search_tc->is_subtype_of('Object')) {
-        if ($search_tc->isa('Moose::Meta::TypeConstraint::Class')) {
-            $class = $search_tc->class;
-            last;
+    if ($tc->can('is_subtype_of')) { # Union can't
+        my $search_tc = $tc;
+        while (1) {
+            if ($search_tc->isa('Moose::Meta::TypeConstraint::Class')) {
+                $class = $search_tc->class;
+                last;
+            }
+            $search_tc = $search_tc->parent;
+            last unless $search_tc->is_subtype_of('Object');
         }
-        $search_tc = $search_tc->parent;
     }
         
     my $inv = (