Make sure to preserve existing metaclass settings for the old meta
Dave Rolsky [Thu, 21 Aug 2008 16:37:35 +0000 (16:37 +0000)]
object (which could be set via metaclass.pm, policies, etc).

lib/MooseX/StrictConstructor.pm

index a1c4a5d..c5bab4e 100644 (file)
@@ -23,7 +23,9 @@ sub init_meta
 
     my $caller = $p{for_class};
 
-    my $metameta = $caller->meta()->meta();
+    my $old_meta = $caller->meta();
+
+    my $metameta = $old_meta->meta();
     unless ( $metameta->can('does_role')
              && $metameta->does_role( 'MooseX::StrictConstructor::Role::Metaclass' ) )
     {
@@ -36,7 +38,13 @@ sub init_meta
 
         Class::MOP::remove_metaclass_by_name($caller);
 
-        $new_meta->name()->initialize($caller);
+        $new_meta->name()->initialize( $caller,
+                                       map { $_ => $old_meta->$_() }
+                                       qw( attribute_metaclass
+                                           method_metaclass
+                                           instance_metaclass
+                                         )
+                                     );
     }
 
     unless ( $caller->meta()->does_role('MooseX::StrictConstructor::Role::Object') )