From: Dave Rolsky <autarch@urth.org>
Date: Mon, 19 Jul 2010 17:11:33 +0000 (-0500)
Subject: Always check that a constraint has a coercion before calling ->coerce
X-Git-Tag: 1.09~12
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5aab256d5db9e8280781c89158a700bfe897389a;p=gitmo%2FMoose.git

Always check that a constraint has a coercion before calling ->coerce
---

diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm
index 0246259..9862765 100644
--- a/lib/Moose/Meta/Attribute.pm
+++ b/lib/Moose/Meta/Attribute.pm
@@ -731,7 +731,7 @@ sub _coerce_and_verify {
     return $val unless $self->has_type_constraint;
 
     $val = $self->type_constraint->coerce($val)
-        if $self->should_coerce;
+        if $self->should_coerce && $self->type_constraint->has_coercion;
 
     $self->verify_against_type_constraint($val, instance => $instance);
 
diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm
index 68de04a..9550412 100644
--- a/lib/Moose/Meta/Method/Constructor.pm
+++ b/lib/Moose/Meta/Method/Constructor.pm
@@ -242,7 +242,7 @@ sub _generate_slot_initializer {
 
             push @source => ('my $val = $params->{\'' . $init_arg . '\'};');
             if ($is_moose && $attr->has_type_constraint) {
-                if ($attr->should_coerce) {
+                if ($attr->should_coerce && $attr->type_constraint->has_coercion) {
                     push @source => $self->_generate_type_coercion(
                         $attr,
                         '$type_constraints[' . $index . ']',
@@ -307,7 +307,7 @@ sub _generate_type_constraint_and_coercion {
     return unless $attr->has_type_constraint;
 
     my @source;
-    if ($attr->should_coerce) {
+    if ($attr->should_coerce && $attr->type_constraint->has_coercion) {
         push @source => $self->_generate_type_coercion(
             $attr,
             '$type_constraints[' . $index . ']',