this may cause issues should be helpful. Metaclasses (classes that inherit
from L<Class::MOP::Object>) are currently exempt from this check, since at the
moment we aren't very consistent about which metaclasses we immutabilize.
+Anonymous classes are also exempt, since they are often created automatically,
+and the user is never given a choice about whether or not to make them
+immutable. If you're sure you know what you're doing, you also can pass the
+C<allow_mutable_ancestors> option to make_immutable to silence the warning
+(but be aware that modifying those mutable ancestors can still lead to
+incorrect behavior in your subclass).
=back
my ( $self, @args ) = @_;
$self->SUPER::_immutable_options(
+ allow_mutable_ancestors => 0,
inline_destructor => 1,
# Moose always does this when an attribute is created
sub make_immutable {
my $self = shift;
+ my %args = @_;
# we do this for metaclasses way too often to do this check for them
- if ( !$self->name->isa('Class::MOP::Object') ) {
+ if ( !$args{allow_mutable_ancestors}
+ && !$self->name->isa('Class::MOP::Object') ) {
my @superclasses = grep { $_ ne 'Moose::Object' && $_ ne $self->name }
$self->linearized_isa;
Also, since Moose always inlines attributes, it sets the
C<inline_accessors> option to false.
+It also accepts the additional C<allow_mutable_ancestors> option, to
+silence the warning you get when trying to make a class with mutable
+ancestors immutable.
+
=item B<< $metaclass->new_object(%params) >>
This overrides the parent's method in order to add support for
BEGIN {
eval "use Test::Output;";
plan skip_all => "Test::Output is required for this test" if $@;
- plan tests => 5;
+ plan tests => 6;
}
{
__PACKAGE__->meta->make_immutable
} '', "no warning when ancestor is a base-class role subclass of Moose::Object";
}
+
+{
+ package Foo::Sub4;
+ use Moose;
+ extends 'Foo';
+
+ ::stderr_is {
+ __PACKAGE__->meta->make_immutable(allow_mutable_ancestors => 1)
+ } '',
+ "no warning when allow_mutable_ancestors => 1 is passed";
+}