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