improve delegation
Matt S Trout [Fri, 18 May 2012 13:30:44 +0000 (13:30 +0000)]
lib/MooseX/Types/TypeDecorator.pm

index 2b9398e..a509a89 100644 (file)
@@ -116,7 +116,10 @@ handle $self->isa since AUTOLOAD can't.
 
 =cut
 
-sub isa { shift->_try_delegate('isa', @_) }
+sub isa {
+  return 1 if $_[1]->isa('Moose::Meta::TypeConstraint');
+  shift->_try_delegate('isa', @_)
+}
 
 =head2 can
 
@@ -171,8 +174,12 @@ sub _try_delegate {
     my $tc = $self->__type_constraint;
     my $inv = (
         $tc->isa('Moose::Meta::TypeConstraint::Class')
-            ? $self->__type_constraint->class
-            : $self->__type_constraint
+            ? (
+                $method eq 'new' || $tc->class->can($method)
+                    ? $tc->class
+                    : $tc
+              )
+            : $tc
     );
     $inv->$method(@args);
 }