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