Explicitly set the constraint for role type
Dave Rolsky [Fri, 15 Apr 2011 15:37:21 +0000 (10:37 -0500)]
lib/Moose/Meta/TypeConstraint/Role.pm

index b8e375a..51951b1 100644 (file)
@@ -17,7 +17,11 @@ sub new {
     my ( $class, %args ) = @_;
 
     $args{parent} = Moose::Util::TypeConstraints::find_type_constraint('Object');
-    my $self      = $class->_new(\%args);
+
+    my $role_name = $args{role};
+    $args{constraint} = sub { Moose::Util::does_role( $_[0], $role_name ) };
+
+    my $self = $class->_new( \%args );
 
     $self->_create_hand_optimized_type_constraint;
     $self->compile_type_constraint();