Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 010_basics / 004_inner_and_augment.t
CommitLineData
60ad2cb7 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
9864f0e4 6use Test::More tests => 16;
60ad2cb7 7use Test::Exception;
8
9
9864f0e4 10
60ad2cb7 11{
12 package Foo;
13 use Mouse;
14
15 sub foo { 'Foo::foo(' . (inner() || '') . ')' }
16 sub bar { 'Foo::bar(' . (inner() || '') . ')' }
17 sub baz { 'Foo::baz(' . (inner() || '') . ')' }
18
19 package Bar;
20 use Mouse;
21
22 extends 'Foo';
23
24 augment foo => sub { 'Bar::foo(' . (inner() || '') . ')' };
25 augment bar => sub { 'Bar::bar' };
26
27 no Mouse; # ensure inner() still works after unimport
28
29 package Baz;
30 use Mouse;
31
32 extends 'Bar';
33
34 augment foo => sub { 'Baz::foo' };
35 augment baz => sub { 'Baz::baz' };
36
37 # this will actually never run,
38 # because Bar::bar does not call inner()
39 augment bar => sub { 'Baz::bar' };
40}
41
42my $baz = Baz->new();
43isa_ok($baz, 'Baz');
44isa_ok($baz, 'Bar');
45isa_ok($baz, 'Foo');
46
47is($baz->foo(), 'Foo::foo(Bar::foo(Baz::foo))', '... got the right value from &foo');
48is($baz->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
49is($baz->baz(), 'Foo::baz(Baz::baz)', '... got the right value from &baz');
50
51my $bar = Bar->new();
52isa_ok($bar, 'Bar');
53isa_ok($bar, 'Foo');
54
55is($bar->foo(), 'Foo::foo(Bar::foo())', '... got the right value from &foo');
56is($bar->bar(), 'Foo::bar(Bar::bar)', '... got the right value from &bar');
57is($bar->baz(), 'Foo::baz()', '... got the right value from &baz');
58
59my $foo = Foo->new();
60isa_ok($foo, 'Foo');
61
62is($foo->foo(), 'Foo::foo()', '... got the right value from &foo');
63is($foo->bar(), 'Foo::bar()', '... got the right value from &bar');
64is($foo->baz(), 'Foo::baz()', '... got the right value from &baz');
65
66# some error cases
67
68{
69 package Bling;
70 use Mouse;
71
72 sub bling { 'Bling::bling' }
73
74 package Bling::Bling;
75 use Mouse;
76
77 extends 'Bling';
78
79 sub bling { 'Bling::bling' }
80
81 ::dies_ok {
82 augment 'bling' => sub {};
83 } '... cannot augment a method which has a local equivalent';
84
85}
86