From: Yuval Kogman Date: Sat, 21 Jun 2008 14:29:55 +0000 (+0000) Subject: more null_constraint checks X-Git-Tag: 0_55~103 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5981f07c486ecc93848bb7953085f84a19d3a25;p=gitmo%2FMoose.git more null_constraint checks --- diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index c7d6c16..21834fe 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -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) {