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