From: Jesse Luehrs Date: Sat, 17 Sep 2011 17:58:54 +0000 (-0500) Subject: overriding types with class_type or role_type should die too X-Git-Tag: 2.0300~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c8bb956ae5fe3e5f336403864234a4437df18c46;p=gitmo%2FMoose.git overriding types with class_type or role_type should die too --- diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index c436d61..6e4e2fa 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -155,6 +155,15 @@ sub create_class_type_constraint { #find_type_constraint("ClassName")->check($class) # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name"); + if (my $type = $REGISTRY->get_type_constraint($class)) { + my $pkg_defined_in = scalar( caller(1) ); + _confess( + "The type constraint '$class' has already been created in " + . $type->_package_defined_in + . " and cannot be created again in " + . $pkg_defined_in ) + } + my %options = ( class => $class, name => $class, @@ -175,6 +184,15 @@ sub create_role_type_constraint { #find_type_constraint("ClassName")->check($class) # || __PACKAGE__->_throw_error("Can't create a class type constraint because '$class' is not a class name"); + if (my $type = $REGISTRY->get_type_constraint($role)) { + my $pkg_defined_in = scalar( caller(1) ); + _confess( + "The type constraint '$role' has already been created in " + . $type->_package_defined_in + . " and cannot be created again in " + . $pkg_defined_in ) + } + my %options = ( role => $role, name => $role,