roles
[gitmo/Moose.git] / t / 012_super_and_override.t
CommitLineData
b6fe348f 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
159da176 6use Test::More tests => 16;
b6fe348f 7
8BEGIN {
9 use_ok('Moose');
10}
11
12{
13 package Foo;
14 use strict;
15 use warnings;
16 use Moose;
17
18 sub foo { 'Foo::foo' }
19 sub bar { 'Foo::bar' }
20 sub baz { 'Foo::baz' }
21
22 package Bar;
23 use strict;
24 use warnings;
25 use Moose;
26
27 extends 'Foo';
28
29 override bar => sub { 'Bar::bar -> ' . super() };
30
31 package Baz;
32 use strict;
33 use warnings;
34 use Moose;
35
36 extends 'Bar';
37
159da176 38 override bar => sub { 'Baz::bar -> ' . super() };
b6fe348f 39 override baz => sub { 'Baz::baz -> ' . super() };
40}
41
42my $baz = Baz->new();
43isa_ok($baz, 'Baz');
44isa_ok($baz, 'Bar');
45isa_ok($baz, 'Foo');
46
47is($baz->foo(), 'Foo::foo', '... got the right value from &foo');
159da176 48is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', '... got the right value from &bar');
b6fe348f 49is($baz->baz(), 'Baz::baz -> Foo::baz', '... got the right value from &baz');
159da176 50
51my $bar = Bar->new();
52isa_ok($bar, 'Bar');
53isa_ok($bar, 'Foo');
54
55is($bar->foo(), 'Foo::foo', '... got the right value from &foo');
56is($bar->bar(), 'Bar::bar -> Foo::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');