Commit | Line | Data |
47e5060c |
1 | use strict; |
2 | use warnings; |
3 | use Test::More; |
4 | use Test::Fatal; |
5 | |
6 | { |
7 | package MooParent; |
8 | use Moo; |
9 | |
10 | has foo => ( |
11 | is => 'ro', |
12 | default => sub { 'MooParent' }, |
13 | ); |
14 | } |
15 | { |
16 | package MooseChild; |
17 | use Moose; |
18 | extends 'MooParent'; |
19 | |
20 | has '+foo' => ( |
21 | default => 'MooseChild', |
22 | ); |
23 | } |
6e77b8df |
24 | { |
25 | package MooseChild2; |
26 | use Moose; |
27 | extends 'MooParent'; |
28 | |
29 | has '+foo' => ( |
30 | default => 'MooseChild2', |
31 | ); |
32 | __PACKAGE__->meta->make_immutable |
33 | } |
b6ab6837 |
34 | { |
35 | package MooChild; |
36 | use Moo; |
37 | extends 'MooParent'; |
38 | |
39 | has '+foo' => ( |
40 | default => sub { 'MooChild' }, |
41 | ); |
42 | } |
47e5060c |
43 | |
44 | is( |
45 | MooseChild->new->foo, |
46 | 'MooseChild', |
47 | 'default value in Moose child' |
48 | ); |
49 | |
6e77b8df |
50 | is( |
51 | MooseChild2->new->foo, |
52 | 'MooseChild2', |
53 | 'default value in Moose child' |
54 | ); |
55 | |
b6ab6837 |
56 | is(exception { |
57 | local $SIG{__WARN__} = sub { die $_[0] }; |
58 | ok(MooChild->meta->has_attribute('foo'), 'inflated metaclass has overridden attribute'); |
59 | }, undef, 'metaclass inflation of plus override works without warnings'); |
60 | |
47e5060c |
61 | done_testing; |
62 | |