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