make accessors use the inlined type checks
Jesse Luehrs [Sat, 17 Apr 2010 03:23:53 +0000 (22:23 -0500)]
lib/Moose/Meta/Method/Accessor.pm
lib/Moose/Meta/TypeConstraint.pm

index 32ec17f..2a63303 100644 (file)
@@ -129,7 +129,12 @@ sub _inline_check_constraint {
 
     my $attr_name = quotemeta( $attr->name );
 
-    qq{\$type_constraint->($value) || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) does not pass the type constraint because: " . \$type_constraint_obj->get_message($value)}, "data => $value") . ";";
+    my $tc = $attr->type_constraint;
+    my $check = $tc->has_hand_optimized_inline_type_constraint
+                    ? $tc->inline_check_of($value, '$type_constraint')
+                    : qq{\$type_constraint->($value)};
+
+    qq{$check || } . $self->_inline_throw_error(qq{"Attribute ($attr_name) does not pass the type constraint because: " . \$type_constraint_obj->get_message($value)}, "data => $value") . ";";
 }
 
 sub _inline_check_coercion {
index fc2766f..27f04c3 100644 (file)
@@ -344,7 +344,7 @@ sub inline_check_of {
     my ($self, $value_var, $constraint_var) = @_;
     $constraint_var ||= '$constraint';
     $value_var      ||= '$_';
-    if ($self->has_hand_optimized_type_constraint) {
+    if ($self->has_hand_optimized_inline_type_constraint) {
         return 'do { local @_ = ('
             . $value_var
             . ');'