From: Tomas Doran Date: Thu, 15 Dec 2011 17:11:42 +0000 (+0000) Subject: And the same fix for role_type X-Git-Tag: 2.0500~89 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7b1df68088e469b2a573298e35a55db92e39b95c;p=gitmo%2FMoose.git And the same fix for role_type --- diff --git a/Changes b/Changes index f9f9ccb..15e5831 100644 --- a/Changes +++ b/Changes @@ -5,9 +5,9 @@ for, noteworthy changes. [BUG FIXES] - * Re-declaring a class_type constraint that has been already declared - now just returns the original type constraint, rather than replacing - the original constraint and ergo losing any coercions that were on + * Re-declaring a class_type or role_type constraint that has already been + declared now just returns the original type constraint, rather than + replacing the original constraint and ergo losing any coercions that were on the original constraint. (t0m) 2.0402 Sat, Feb 04, 2012 diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index bcd9f97..b44a0eb 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -201,6 +201,9 @@ sub create_role_type_constraint { . " and cannot be created again in " . $pkg_defined_in ) } + else { + return $type; + } } my %options = ( diff --git a/t/type_constraints/role_type_constraint.t b/t/type_constraints/role_type_constraint.t index ea6b34d..23828f6 100644 --- a/t/type_constraints/role_type_constraint.t +++ b/t/type_constraints/role_type_constraint.t @@ -61,4 +61,10 @@ ok( $type->equals(Moose::Meta::TypeConstraint::Role->new( name => "Oink", role = ok( !$type->equals(Moose::Meta::TypeConstraint::Role->new( name => "__ANON__", role => "Bar" )), "doesn't equal other anon constraint" ); ok( $type->is_subtype_of(Moose::Meta::TypeConstraint::Role->new( name => "__ANON__", role => "Bar" )), "subtype of other anon constraint" ); +{ # See block comment in t/type_constraints/class_type_constraint.t + my $type; + is( exception { $type = role_type 'MyExampleRole' }, undef, 'Make initial role_type' ); + is( exception { is(role_type('MyExampleRole'), $type, 're-running role_type gives same type') }, undef, 'No exception making duplicate role_type' );; +} + done_testing;