Add support for Type in native traits topic/works-with-Type
Dave Rolsky [Sun, 30 Sep 2012 16:55:37 +0000 (11:55 -0500)]
lib/Moose/Meta/Method/Accessor/Native/Collection.pm
lib/Moose/Meta/Method/Accessor/Native/Writer.pm

index ffed041..cd58f4b 100644 (file)
@@ -87,7 +87,8 @@ sub _check_new_members_only {
     # constraint, so we need to check the whole value, not just the members.
     return 1
         if $self->_is_root_type( $tc->parent )
-            && $tc->isa('Moose::Meta::TypeConstraint::Parameterized');
+            && ( $tc->isa('Moose::Meta::TypeConstraint::Parameterized')
+                 || $tc->isa('Type::Constraint::Parameterized') );
 
     return 0;
 }
index 57a4a70..2b55aae 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use List::MoreUtils qw( any );
+use Moose::Util;
 
 use Moose::Role;
 
@@ -85,11 +86,20 @@ sub _constraint_must_be_checked {
 
 sub _is_root_type {
     my $self = shift;
-    my ($type) = @_;
-
-    my $name = $type->name;
-
-    return any { $name eq $_ } @{ $self->root_types };
+    my $type = shift;
+
+    if (
+        Moose::Util::does_role( $type, 'Type::Constraint::Role::Interface' ) )
+    {
+        require Type::Library::Builtins;
+        return
+            any { $type->is_same_type_as( Type::Library::Builtins::t($_) ) }
+        @{ $self->root_types };
+    }
+    else {
+        my $name = $type->name;
+        return any { $name eq $_ } @{ $self->root_types };
+    }
 }
 
 sub _inline_copy_native_value {