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