class_type shouldn't load the class (Moose compat; no easy fix :/)
[gitmo/Mouse.git] / lib / Mouse / Util / TypeConstraints.pm
index 732797f..09f5077 100644 (file)
@@ -90,7 +90,7 @@ my $optimized_constraints_base;
 sub _type {
     my $pkg = caller(0);
     my($name, %conf) = @_;
-    if (my $type = $TYPE{$name}) {
+    if ($TYPE{$name} && $TYPE_SOURCE{$name} ne $pkg) {
         Carp::croak "The type constraint '$name' has already been created in $TYPE_SOURCE{$name} and cannot be created again in $pkg";
     };
     my $constraint = $conf{where} || do { $TYPE{delete $conf{as} || 'Any' } };
@@ -102,7 +102,7 @@ sub _type {
 sub _subtype {
     my $pkg = caller(0);
     my($name, %conf) = @_;
-    if (my $type = $TYPE{$name}) {
+    if ($TYPE{$name} && $TYPE_SOURCE{$name} ne $pkg) {
         Carp::croak "The type constraint '$name' has already been created in $TYPE_SOURCE{$name} and cannot be created again in $pkg";
     };
     my $constraint = $conf{where} || do { $TYPE{delete $conf{as} || 'Any' } };
@@ -143,7 +143,6 @@ sub _class_type {
     my $pkg = caller(0);
     my($name, $conf) = @_;
     my $class = $conf->{class};
-    Mouse::load_class($class);
     _subtype(
         $name => where => sub { $_->isa($class) }
     );