roles
[gitmo/Moose.git] / t / 013_inner_and_augment.t
CommitLineData
b6fe348f 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
159da176 6use Test::More tests => 16;
b6fe348f 7
8BEGIN {
9 use_ok('Moose');
10}
11
12{
13 package Foo;
14 use strict;
15 use warnings;
16 use Moose;
17
159da176 18 sub foo { 'Foo::foo(' . (inner() || '') . ')' }
19 sub bar { 'Foo::bar(' . (inner() || '') . ')' }
20 sub baz { 'Foo::baz(' . (inner() || '') . ')' }
b6fe348f 21
22 package Bar;
23 use strict;
24 use warnings;
25 use Moose;
26
27 extends 'Foo';
28
159da176 29 augment foo => sub { 'Bar::foo(' . (inner() || '') . ')' };
b6fe348f 30 augment bar => sub { 'Bar::bar' };
31
32 package Baz;
33 use strict;
34 use warnings;
35 use Moose;
36
37 extends 'Bar';
38
39 augment foo => sub { 'Baz::foo' };
40 augment baz => sub { 'Baz::baz' };
159da176 41
42 # this will actually never run,
43 # because Bar::bar does not call inner()
44 augment bar => sub { 'Baz::bar' };
b6fe348f 45}
46
47my $baz = Baz->new();
48isa_ok($baz, 'Baz');
49isa_ok($baz, 'Bar');
50isa_ok($baz, 'Foo');
51
52is($baz->foo(), 'Foo::foo(Bar::foo(Baz::foo))', '... got the right value from &foo');
53is($baz->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
54is($baz->baz(), 'Foo::baz(Baz::baz)', '... got the right value from &baz');
55
159da176 56my $bar = Bar->new();
57isa_ok($bar, 'Bar');
58isa_ok($bar, 'Foo');
59
60is($bar->foo(), 'Foo::foo(Bar::foo())', '... got the right value from &foo');
61is($bar->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
62is($bar->baz(), 'Foo::baz()', '... got the right value from &baz');
63
64my $foo = Foo->new();
65isa_ok($foo, 'Foo');
66
67is($foo->foo(), 'Foo::foo()', '... got the right value from &foo');
68is($foo->bar(), 'Foo::bar()', '... got the right value from &bar');
69is($foo->baz(), 'Foo::baz()', '... got the right value from &baz');