From: Jesse Luehrs Date: Sat, 17 Apr 2010 03:23:53 +0000 (-0500) Subject: make accessors use the inlined type checks X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7fe477f8dc3c669bee408013c79d792fff50d312;p=gitmo%2FMoose.git make accessors use the inlined type checks --- diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 32ec17f..2a63303 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -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 { diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index fc2766f..27f04c3 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -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 . ');'