Commit | Line | Data |
098a367b |
1 | use strictures 1; |
2 | use Test::More; |
3 | |
4 | my @ran; |
5 | |
6 | { |
b1eebd55 |
7 | package Foo; use Moo; sub BUILD { push @ran, 'Foo' } |
8 | package Bar; use Moo; extends 'Foo'; sub BUILD { push @ran, 'Bar' } |
9 | package Baz; use Moo; extends 'Bar'; |
10 | package Quux; use Moo; extends 'Baz'; sub BUILD { push @ran, 'Quux' } |
098a367b |
11 | } |
12 | |
077bd026 |
13 | { |
14 | package Fleem; |
b1eebd55 |
15 | use Moo; |
077bd026 |
16 | extends 'Quux'; |
17 | has 'foo' => (is => 'ro'); |
18 | sub BUILD { push @ran, $_[0]->foo, $_[1]->{bar} } |
19 | } |
20 | |
c4570291 |
21 | { |
22 | package Odd1; |
23 | use Moo; |
24 | has 'odd1' => (is => 'ro'); |
25 | sub BUILD { push @ran, 'Odd1' } |
26 | package Odd2; |
27 | use Moo; |
28 | extends 'Odd1'; |
29 | package Odd3; |
30 | use Moo; |
31 | extends 'Odd2'; |
32 | has 'odd3' => (is => 'ro'); |
33 | sub BUILD { push @ran, 'Odd3' } |
34 | } |
35 | |
e0e12d16 |
36 | { |
37 | package Sub1; |
38 | use Moo; |
39 | has 'foo' => (is => 'ro'); |
40 | package Sub2; |
41 | use Moo; |
42 | extends 'Sub1'; |
43 | sub BUILD { push @ran, "sub2" } |
44 | } |
45 | |
098a367b |
46 | my $o = Quux->new; |
47 | |
48 | is(ref($o), 'Quux', 'object returned'); |
49 | is_deeply(\@ran, [ qw(Foo Bar Quux) ], 'BUILDs ran in order'); |
50 | |
077bd026 |
51 | @ran = (); |
52 | |
53 | $o = Fleem->new(foo => 'Fleem1', bar => 'Fleem2'); |
54 | |
55 | is(ref($o), 'Fleem', 'object with inline constructor returned'); |
56 | is_deeply(\@ran, [ qw(Foo Bar Quux Fleem1 Fleem2) ], 'BUILDs ran in order'); |
57 | |
c4570291 |
58 | @ran = (); |
59 | |
60 | $o = Odd3->new(odd1 => 1, odd3 => 3); |
61 | |
62 | is(ref($o), 'Odd3', 'Odd3 object constructed'); |
63 | is_deeply(\@ran, [ qw(Odd1 Odd3) ], 'BUILDs ran in order'); |
64 | |
e0e12d16 |
65 | @ran = (); |
66 | |
67 | $o = Sub2->new; |
68 | |
69 | is(ref($o), 'Sub2', 'Sub2 object constructed'); |
70 | is_deeply(\@ran, [ qw(sub2) ], 'BUILD ran'); |
71 | |
098a367b |
72 | done_testing; |