Make sure weak attributes remain weak when cloning (Moose 2.0007)
[gitmo/Mouse.git] / lib / Mouse / Meta / Method / Constructor.pm
index 94acd0d..610e98a 100644 (file)
@@ -1,7 +1,7 @@
 package Mouse::Meta::Method::Constructor;
 use Mouse::Util qw(:meta); # enables strict and warnings
 
-use constant _MOUSE_DEBUG => !!$ENV{MOUSE_DEBUG};
+use constant _MOUSE_DEBUG => $ENV{MOUSE_DEBUG} ? 1 : 0;
 
 sub _inline_slot{
     my(undef, $self_var, $attr_name) = @_;
@@ -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;
     }
 
@@ -232,7 +233,7 @@ Mouse::Meta::Method::Constructor - A Mouse method generator for constructors
 
 =head1 VERSION
 
-This document describes Mouse version 0.82
+This document describes Mouse version 0.92
 
 =head1 SEE ALSO