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
|
use strict;
use warnings;
use Test::More;
{
package Foo;
use Moose;
has foo => (is => 'ro');
}
{
package Foo::Sub;
use Moose;
extends 'Foo';
has bar => (is => 'ro');
}
{
my $foo = Foo::Sub->new(foo => 12, bar => 25);
is($foo->foo, 12, 'got right value for foo');
is($foo->bar, 25, 'got right value for bar');
}
Foo->meta->make_immutable;
{
package Foo::Sub2;
use Moose;
extends 'Foo';
has baz => (is => 'ro');
# not making immutable, inheriting Foo's inlined constructor
}
{
my $foo = Foo::Sub2->new(foo => 42, baz => 27);
is($foo->foo, 42, 'got right value for foo');
is($foo->baz, 27, 'got right value for baz');
}
my $BAR = 0;
{
package Bar;
use Moose;
}
{
package Bar::Sub;
use Moose;
extends 'Bar';
sub DEMOLISH { $BAR++ }
}
Bar::Sub->new;
is($BAR, 1, 'DEMOLISH in subclass was called');
$BAR = 0;
Bar->meta->make_immutable;
{
package Bar::Sub2;
use Moose;
extends 'Bar';
sub DEMOLISH { $BAR++ }
# not making immutable, inheriting Bar's inlined destructor
}
Bar::Sub2->new;
is($BAR, 1, 'DEMOLISH in subclass was called');
done_testing;
|