Use fewer assignments when doing a coercion in the constructor
Shawn M Moore [Wed, 3 Dec 2008 03:58:01 +0000 (03:58 +0000)]
lib/Mouse/Meta/Method/Constructor.pm

index c0cf03e..103cd31 100644 (file)
@@ -40,10 +40,11 @@ sub _generate_processattrs {
         my $part1 = do {
             my @code;
 
-            push @code, "my \$value = \$args->{'$from'};";
-
             if ($attr->should_coerce) {
-                push @code, "\$value = \$attr->coerce_constraint( \$value );";
+                push @code, "my \$value = \$attr->coerce_constraint( \$args->{'$from'});";
+            }
+            else {
+                push @code, "my \$value = \$args->{'$from'};";
             }
 
             if ($attr->has_type_constraint) {