Always check that a constraint has a coercion before calling ->coerce
Dave Rolsky [Mon, 19 Jul 2010 17:11:33 +0000 (12:11 -0500)]
lib/Moose/Meta/Attribute.pm
lib/Moose/Meta/Method/Constructor.pm

index 0246259..9862765 100644 (file)
@@ -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);
 
index 68de04a..9550412 100644 (file)
@@ -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 . ']',