my $old_metaclass = blessed($options{package})
? $options{package}
: Class::MOP::get_metaclass_by_name($options{package});
+ $old_metaclass->_remove_generated_metaobjects
+ if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
my $new_metaclass = $class->SUPER::reinitialize(@args);
$new_metaclass->_restore_metaobjects_from($old_metaclass)
- if $old_metaclass;
+ if $old_metaclass && $old_metaclass->isa('Class::MOP::Class');
return $new_metaclass;
}
}
}
+sub _remove_generated_metaobjects {
+ my $self = shift;
+
+ for my $attr (map { $self->get_attribute($_) } $self->get_attribute_list) {
+ $attr->remove_accessors;
+ }
+}
+
## ANON classes
{
_get_compatible_single_metaclass_by_subclassing
_get_compatible_single_metaclass
_make_metaobject_compatible
+ _remove_generated_metaobjects
_restore_metaobjects_from
add_meta_instance_dependencies remove_meta_instance_dependencies update_meta_instance_dependencies
);
} qr/compatible/;
+{
+ package Quuux::Meta::Attribute;
+ use base 'Class::MOP::Attribute';
+
+ sub install_accessors {}
+}
+
+{
+ package Quuux;
+ use metaclass;
+ sub foo {}
+ Quuux->meta->add_attribute('bar', reader => 'bar');
+}
+
+$meta = Quuux->meta;
+check_meta_sanity($meta, 'Quuux');
+ok($meta->has_method('bar'));
+lives_ok {
+ $meta = $meta->reinitialize(
+ 'Quuux',
+ attribute_metaclass => 'Quuux::Meta::Attribute',
+ );
+};
+check_meta_sanity($meta, 'Quuux');
+ok(!$meta->has_method('bar'));
+
done_testing;