Skip distro which requires rpm
[gitmo/Moose.git] / t / basics / override_augment_inner_super.t
CommitLineData
05d9eaf6 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use 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
33my $baz = Baz->new();
34isa_ok($baz, 'Baz');
35isa_ok($baz, 'Bar');
36isa_ok($baz, 'Foo');
37
38=pod
39
d03bd989 40Let em clarify what is happening here. Baz::foo is calling
41super(), which calls Bar::foo, which is an augmented sub
42that calls Foo::foo, then calls inner() which actually
43then calls Bar::foo. Confusing I know,.. but this is
05d9eaf6 44*exactly* what is it supposed to do :)
45
46=cut
47
d03bd989 48is($baz->foo,
49 'Baz::foo -> Foo::foo(Bar::foo)',
05d9eaf6 50 '... got the right value from mixed augment/override foo');
51
52=pod
53
54Allow me to clarify this one now ...
55
d03bd989 56Since Baz::bar is an augment routine, it needs to find the
05d9eaf6 57correct inner() to be called by. In this case it is Foo::bar.
6549b0d1 58However, Bar::bar is in-between us, so it should actually be
05d9eaf6 59called first. Bar::bar is an overriden sub, and calls super()
d03bd989 60which in turn then calls our Foo::bar, which calls inner(),
05d9eaf6 61which calls Baz::bar.
62
63Confusing I know, but it is correct :)
64
65=cut
66
d03bd989 67is($baz->bar,
68 'Bar::bar -> Foo::bar(Baz::bar)',
05d9eaf6 69 '... got the right value from mixed augment/override bar');
a28e50e4 70
71done_testing;