Commit | Line | Data |
05d9eaf6 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
05d9eaf6 |
7 | |
05d9eaf6 |
8 | |
9 | { |
10 | package Foo; |
05d9eaf6 |
11 | use Moose; |
d03bd989 |
12 | |
05d9eaf6 |
13 | sub foo { 'Foo::foo(' . (inner() || '') . ')' }; |
14 | sub bar { 'Foo::bar(' . (inner() || '') . ')' } |
d03bd989 |
15 | |
05d9eaf6 |
16 | package Bar; |
05d9eaf6 |
17 | use Moose; |
d03bd989 |
18 | |
05d9eaf6 |
19 | extends 'Foo'; |
d03bd989 |
20 | |
05d9eaf6 |
21 | augment 'foo' => sub { 'Bar::foo' }; |
d03bd989 |
22 | override 'bar' => sub { 'Bar::bar -> ' . super() }; |
23 | |
05d9eaf6 |
24 | package Baz; |
05d9eaf6 |
25 | use Moose; |
d03bd989 |
26 | |
05d9eaf6 |
27 | extends 'Bar'; |
d03bd989 |
28 | |
05d9eaf6 |
29 | override 'foo' => sub { 'Baz::foo -> ' . super() }; |
30 | augment 'bar' => sub { 'Baz::bar' }; |
31 | } |
32 | |
33 | my $baz = Baz->new(); |
34 | isa_ok($baz, 'Baz'); |
35 | isa_ok($baz, 'Bar'); |
36 | isa_ok($baz, 'Foo'); |
37 | |
38 | =pod |
39 | |
d03bd989 |
40 | Let em clarify what is happening here. Baz::foo is calling |
41 | super(), which calls Bar::foo, which is an augmented sub |
42 | that calls Foo::foo, then calls inner() which actually |
43 | then calls Bar::foo. Confusing I know,.. but this is |
05d9eaf6 |
44 | *exactly* what is it supposed to do :) |
45 | |
46 | =cut |
47 | |
d03bd989 |
48 | is($baz->foo, |
49 | 'Baz::foo -> Foo::foo(Bar::foo)', |
05d9eaf6 |
50 | '... got the right value from mixed augment/override foo'); |
51 | |
52 | =pod |
53 | |
54 | Allow me to clarify this one now ... |
55 | |
d03bd989 |
56 | Since Baz::bar is an augment routine, it needs to find the |
05d9eaf6 |
57 | correct inner() to be called by. In this case it is Foo::bar. |
6549b0d1 |
58 | However, Bar::bar is in-between us, so it should actually be |
05d9eaf6 |
59 | called first. Bar::bar is an overriden sub, and calls super() |
d03bd989 |
60 | which in turn then calls our Foo::bar, which calls inner(), |
05d9eaf6 |
61 | which calls Baz::bar. |
62 | |
63 | Confusing I know, but it is correct :) |
64 | |
65 | =cut |
66 | |
d03bd989 |
67 | is($baz->bar, |
68 | 'Bar::bar -> Foo::bar(Baz::bar)', |
05d9eaf6 |
69 | '... got the right value from mixed augment/override bar'); |
a28e50e4 |
70 | |
71 | done_testing; |