Skip distro which requires rpm
[gitmo/Moose.git] / t / basics / override_and_foreign_classes.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7
8
9 =pod
10
11 This just tests the interaction of override/super
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
15 super method.
16
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.
20
21 =cut
22
23 {
24     package Foo;
25     use strict;
26     use warnings;
27
28     sub new { bless {} => shift() }
29
30     sub foo { 'Foo::foo' }
31     sub bar { 'Foo::bar' }
32     sub baz { 'Foo::baz' }
33
34     package Bar;
35     use Moose;
36
37     extends 'Foo';
38
39     override bar => sub { 'Bar::bar -> ' . super() };
40
41     package Baz;
42     use Moose;
43
44     extends 'Bar';
45
46     override bar => sub { 'Baz::bar -> ' . super() };
47     override baz => sub { 'Baz::baz -> ' . super() };
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');
72 is($foo->baz(), 'Foo::baz', '... got the right value from &baz');
73
74 done_testing;