DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 010_basics / 005_override_augment_inner_super.t
CommitLineData
05d9eaf6 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 5;
7
05d9eaf6 8
05d9eaf6 9
10{
11 package Foo;
05d9eaf6 12 use Moose;
d03bd989 13
05d9eaf6 14 sub foo { 'Foo::foo(' . (inner() || '') . ')' };
15 sub bar { 'Foo::bar(' . (inner() || '') . ')' }
d03bd989 16
05d9eaf6 17 package Bar;
05d9eaf6 18 use Moose;
d03bd989 19
05d9eaf6 20 extends 'Foo';
d03bd989 21
05d9eaf6 22 augment 'foo' => sub { 'Bar::foo' };
d03bd989 23 override 'bar' => sub { 'Bar::bar -> ' . super() };
24
05d9eaf6 25 package Baz;
05d9eaf6 26 use Moose;
d03bd989 27
05d9eaf6 28 extends 'Bar';
d03bd989 29
05d9eaf6 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
d03bd989 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
05d9eaf6 45*exactly* what is it supposed to do :)
46
47=cut
48
d03bd989 49is($baz->foo,
50 'Baz::foo -> Foo::foo(Bar::foo)',
1808c2da 51 'got the right value from mixed augment/override foo');
05d9eaf6 52
53=pod
54
55Allow me to clarify this one now ...
56
d03bd989 57Since Baz::bar is an augment routine, it needs to find the
05d9eaf6 58correct inner() to be called by. In this case it is Foo::bar.
6549b0d1 59However, Bar::bar is in-between us, so it should actually be
05d9eaf6 60called first. Bar::bar is an overriden sub, and calls super()
d03bd989 61which in turn then calls our Foo::bar, which calls inner(),
05d9eaf6 62which calls Baz::bar.
63
64Confusing I know, but it is correct :)
65
66=cut
67
d03bd989 68is($baz->bar,
69 'Bar::bar -> Foo::bar(Baz::bar)',
1808c2da 70 'got the right value from mixed augment/override bar');