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