1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
BEGIN {
eval "use Test::Output;";
plan skip_all => "Test::Output is required for this test" if $@;
}
{
package NotMoose;
sub new {
my $class = shift;
return bless { not_moose => 1 }, $class;
}
}
{
package Foo;
use Moose;
extends 'NotMoose';
::stderr_like(
sub { Foo->meta->make_immutable },
qr/\QNot inlining 'new' for Foo since it is not inheriting the default Moose::Object::new\E\s+\QIf you are certain you don't need to inline your constructor, specify inline_constructor => 0 in your call to Foo->meta->make_immutable/,
'got a warning that Foo may not have an inlined constructor'
);
}
is(
Foo->meta->find_method_by_name('new')->body,
NotMoose->can('new'),
'Foo->new is inherited from NotMoose'
);
{
package Bar;
use Moose;
extends 'NotMoose';
::stderr_is(
sub { Bar->meta->make_immutable( replace_constructor => 1 ) },
q{},
'no warning when replace_constructor is true'
);
}
is(
Bar->meta->find_method_by_name('new')->package_name,
'Bar',
'Bar->new is inlined, and not inherited from NotMoose'
);
{
package Baz;
use Moose;
Baz->meta->make_immutable;
}
{
package Quux;
use Moose;
extends 'Baz';
::stderr_is(
sub { Quux->meta->make_immutable },
q{},
'no warning when inheriting from a class that has already made itself immutable'
);
}
{
package My::Constructor;
use base 'Moose::Meta::Method::Constructor';
}
{
package CustomCons;
use Moose;
CustomCons->meta->make_immutable( constructor_class => 'My::Constructor' );
}
{
package Subclass;
use Moose;
extends 'CustomCons';
::stderr_is(
sub { Subclass->meta->make_immutable },
q{},
'no warning when inheriting from a class that has already made itself immutable'
);
}
done_testing;
|