more null_constraint checks
Yuval Kogman [Sat, 21 Jun 2008 14:29:55 +0000 (14:29 +0000)]
lib/Moose/Meta/TypeConstraint.pm

index c7d6c16..21834fe 100644 (file)
@@ -197,14 +197,19 @@ sub _compile_subtype {
     } elsif( $optimized_parent and @parents == 1 ) {
         # the case of just one optimized parent is optimized to prevent
         # looping and the unnecessary localization
-        return Class::MOP::subname($self->name, sub {
-            return undef unless $optimized_parent->($_[0]);
-            local $_ = $_[0];
-            $check->($_[0]);
-        });
+        if ( $check == $null_constraint ) {
+            return $optimized_parent;
+        } else {
+            return Class::MOP::subname($self->name, sub {
+                return undef unless $optimized_parent->($_[0]);
+                local $_ = $_[0];
+                $check->($_[0]);
+            });
+        }
     } else {
         # general case, check all the constraints, from the first parent to ourselves
-        my @checks = ( @parents, $check );
+        my @checks = @parents;
+        push @checks, $check if $check != $null_constraint;
         return Class::MOP::subname($self->name => sub {
             local $_ = $_[0];
             foreach my $check (@checks) {