complain about unsafe fixing, since cmop doesn't anymore
Jesse Luehrs [Mon, 19 Apr 2010 01:50:45 +0000 (20:50 -0500)]
for this specific case, anyway

lib/Moose/Meta/Class.pm
t/050_metaclasses/052_metaclass_compat.t

index a02851a..107dc0f 100644 (file)
@@ -6,7 +6,7 @@ use warnings;
 
 use Class::MOP;
 
-use Carp ();
+use Carp qw( confess );
 use Data::OptList;
 use List::Util qw( first );
 use List::MoreUtils qw( any all uniq first_index );
@@ -537,6 +537,10 @@ sub _fix_class_metaclass_incompatibility {
     $self->SUPER::_fix_class_metaclass_incompatibility(@_);
 
     if ($self->_can_fix_class_metaclass_incompatibility_by_role_reconciliation($super_meta)) {
+        ($self->is_pristine)
+            || confess "Can't fix metaclass incompatibility for "
+                     . $self->name
+                     . " because it is not pristine.";
         my $super_meta_name = $super_meta->is_immutable
                                   ? $super_meta->_get_mutable_metaclass_name
                                   : blessed($super_meta);
@@ -561,6 +565,10 @@ sub _fix_single_metaclass_incompatibility {
     $self->SUPER::_fix_single_metaclass_incompatibility(@_);
 
     if ($self->_can_fix_single_metaclass_incompatibility_by_role_reconciliation($metaclass_type, $super_meta)) {
+        ($self->is_pristine)
+            || confess "Can't fix metaclass incompatibility for "
+                     . $self->name
+                     . " because it is not pristine.";
         my %metaclasses = $self->_base_metaclasses;
         my $class_specific_meta_subclass_meta = $self->_reconcile_roles_for_metaclass($self->$metaclass_type, $super_meta->$metaclass_type);
         my $new_self = $super_meta->reinitialize(
index c2b8ab4..e6d9f45 100644 (file)
@@ -241,4 +241,40 @@ ok(Foo::Sub->meta->constructor_class->meta->can('does_role')
     'MI extends after_generated_methods with metaclass roles (reverse)';
 }
 
+{
+    package Foo6::Meta::Role;
+    use Moose::Role;
+}
+{
+    package Foo6::SuperClass::WithMetaRole;
+    use Moose -traits =>'Foo6::Meta::Role';
+}
+{
+    package Foo6::Meta::OtherRole;
+    use Moose::Role;
+}
+{
+    package Foo6::SuperClass::After::Attribute;
+    use Moose -traits =>'Foo6::Meta::OtherRole';
+}
+{
+    package Foo6;
+    use Moose;
+    my @superclasses = ('Foo6::SuperClass::WithMetaRole');
+    extends @superclasses;
+
+    has an_attribute_generating_methods => ( is => 'ro' );
+
+    push(@superclasses, 'Foo6::SuperClass::After::Attribute');
+
+    ::throws_ok {
+        extends @superclasses;
+    } qr/compat.*pristine/,
+    'unsafe MI extends after_generated_methods with metaclass roles';
+    ::throws_ok {
+        extends reverse @superclasses;
+    } qr/compat.*pristine/,
+    'unsafe MI extends after_generated_methods with metaclass roles (reverse)';
+}
+
 done_testing;