Commit | Line | Data |
05d9eaf6 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
a28e50e4 |
6 | use Test::More; |
05d9eaf6 |
7 | |
05d9eaf6 |
8 | |
9 | =pod |
10 | |
11 | This just tests the interaction of override/super |
d03bd989 |
12 | with non-Moose superclasses. It really should not |
13 | cause issues, the only thing it does is to create |
14 | a metaclass for Foo so that it can find the right |
05d9eaf6 |
15 | super method. |
16 | |
d03bd989 |
17 | This may end up being a sensitive issue for some |
18 | non-Moose classes, but in 99% of the cases it |
19 | should be just fine. |
05d9eaf6 |
20 | |
21 | =cut |
22 | |
23 | { |
24 | package Foo; |
25 | use strict; |
26 | use warnings; |
d03bd989 |
27 | |
05d9eaf6 |
28 | sub new { bless {} => shift() } |
d03bd989 |
29 | |
05d9eaf6 |
30 | sub foo { 'Foo::foo' } |
d03bd989 |
31 | sub bar { 'Foo::bar' } |
05d9eaf6 |
32 | sub baz { 'Foo::baz' } |
d03bd989 |
33 | |
05d9eaf6 |
34 | package Bar; |
05d9eaf6 |
35 | use Moose; |
d03bd989 |
36 | |
05d9eaf6 |
37 | extends 'Foo'; |
d03bd989 |
38 | |
39 | override bar => sub { 'Bar::bar -> ' . super() }; |
40 | |
05d9eaf6 |
41 | package Baz; |
05d9eaf6 |
42 | use Moose; |
d03bd989 |
43 | |
05d9eaf6 |
44 | extends 'Bar'; |
d03bd989 |
45 | |
46 | override bar => sub { 'Baz::bar -> ' . super() }; |
47 | override baz => sub { 'Baz::baz -> ' . super() }; |
05d9eaf6 |
48 | } |
49 | |
50 | my $baz = Baz->new(); |
51 | isa_ok($baz, 'Baz'); |
52 | isa_ok($baz, 'Bar'); |
53 | isa_ok($baz, 'Foo'); |
54 | |
55 | is($baz->foo(), 'Foo::foo', '... got the right value from &foo'); |
56 | is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', '... got the right value from &bar'); |
57 | is($baz->baz(), 'Baz::baz -> Foo::baz', '... got the right value from &baz'); |
58 | |
59 | my $bar = Bar->new(); |
60 | isa_ok($bar, 'Bar'); |
61 | isa_ok($bar, 'Foo'); |
62 | |
63 | is($bar->foo(), 'Foo::foo', '... got the right value from &foo'); |
64 | is($bar->bar(), 'Bar::bar -> Foo::bar', '... got the right value from &bar'); |
65 | is($bar->baz(), 'Foo::baz', '... got the right value from &baz'); |
66 | |
67 | my $foo = Foo->new(); |
68 | isa_ok($foo, 'Foo'); |
69 | |
70 | is($foo->foo(), 'Foo::foo', '... got the right value from &foo'); |
71 | is($foo->bar(), 'Foo::bar', '... got the right value from &bar'); |
a28e50e4 |
72 | is($foo->baz(), 'Foo::baz', '... got the right value from &baz'); |
73 | |
74 | done_testing; |