Regenerate test files
[gitmo/Mouse.git] / t / 010_basics / 005_override_augment_inner_super.t
CommitLineData
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!!!
4use t::lib::MooseCompat;
60ad2cb7 5
6use strict;
7use warnings;
8
fde8e43f 9use 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
37my $baz = Baz->new();
38isa_ok($baz, 'Baz');
39isa_ok($baz, 'Bar');
40isa_ok($baz, 'Foo');
41
42=pod
43
44Let em clarify what is happening here. Baz::foo is calling
45super(), which calls Bar::foo, which is an augmented sub
46that calls Foo::foo, then calls inner() which actually
47then calls Bar::foo. Confusing I know,.. but this is
48*exactly* what is it supposed to do :)
49
50=cut
51
52is($baz->foo,
53 'Baz::foo -> Foo::foo(Bar::foo)',
54 '... got the right value from mixed augment/override foo');
55
56=pod
57
58Allow me to clarify this one now ...
59
60Since Baz::bar is an augment routine, it needs to find the
61correct inner() to be called by. In this case it is Foo::bar.
62However, Bar::bar is in-between us, so it should actually be
63called first. Bar::bar is an overriden sub, and calls super()
64which in turn then calls our Foo::bar, which calls inner(),
65which calls Baz::bar.
66
67Confusing I know, but it is correct :)
68
69=cut
70
fde8e43f 71is($baz->bar,
72 'Bar::bar -> Foo::bar(Baz::bar)',
73 '... got the right value from mixed augment/override bar');
74
75done_testing;