Make sure weak attributes remain weak when cloning (Moose 2.0007)
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Constructor.pm
index fe32939..610e98a 100644 (file)
@@ -87,10 +87,6 @@ sub _generate_initialize_object {
             $post_process .= "\$checks[$index]->($instance_slot)\n";
             $post_process .= "  or $attr_var->_throw_type_constraint_error($instance_slot, $constraint_var);\n";
         }
-        if($is_weak_ref){
-            $post_process  = "Scalar::Util::weaken($instance_slot) "
-                             . "if ref $instance_slot;\n";
-        }
 
         # build cde for an attribute
         if (defined $init_arg) {
@@ -151,6 +147,11 @@ sub _generate_initialize_object {
 
         $code .= "}\n" if defined $init_arg;
 
+        if($is_weak_ref){
+            $code .= "Scalar::Util::weaken($instance_slot) "
+                   . "if ref $instance_slot;\n";
+        }
+
         push @res, $code;
     }