From: Dave Rolsky Date: Sun, 30 Sep 2012 16:55:37 +0000 (-0500) Subject: Add support for Type in native traits X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d85da60f4f8a33dd3a34401e754f9a7a10da3846;p=gitmo%2FMoose.git Add support for Type in native traits --- diff --git a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm index ffed041..cd58f4b 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Collection.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Collection.pm @@ -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; } diff --git a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm index 57a4a70..2b55aae 100644 --- a/lib/Moose/Meta/Method/Accessor/Native/Writer.pm +++ b/lib/Moose/Meta/Method/Accessor/Native/Writer.pm @@ -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 {