like Moose::Meta::Class. This happens when you make your own metaclass
using Moose and then load modules which apply roles to the metaclass.
Also, when making the new metaclass immutable, don't inline the
constructor.
return $class_name
if Class::MOP::is_class_loaded($class_name);
- my $meta = (ref $self)->create(
+ # If the metaclass is a subclass of CMOP::Class which has had
+ # metaclass roles applied (via Moose), then we want to make sure
+ # that we preserve that anonymous class (see Fey::ORM for an
+ # example of where this matters).
+ my $meta_name
+ = $self->meta->is_immutable
+ ? $self->meta->get_mutable_metaclass_name
+ : ref $self->meta;
+
+ my $meta = $meta_name->create(
$class_name,
superclasses => [ ref $self ],
);
}
}
- $meta->make_immutable;
+ $meta->make_immutable( inline_constructor => 0 );
return $class_name;
}