Mouse::Util::does_role() respects $thing->does() method
[gitmo/Mouse.git] / t / 010_basics / 003_super_and_override.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 16;
7 use Test::Exception;
8
9
10
11 {
12     package Foo;
13     use Mouse;
14
15     sub foo { 'Foo::foo' }
16     sub bar { 'Foo::bar' }
17     sub baz { 'Foo::baz' }
18
19     package Bar;
20     use Mouse;
21
22     extends 'Foo';
23
24     override bar => sub { 'Bar::bar -> ' . super() };
25
26     package Baz;
27     use Mouse;
28
29     extends 'Bar';
30
31     override bar => sub { 'Baz::bar -> ' . super() };
32     override baz => sub { 'Baz::baz -> ' . super() };
33
34     no Mouse; # ensure super() still works after unimport
35 }
36
37 my $baz = Baz->new();
38 isa_ok($baz, 'Baz');
39 isa_ok($baz, 'Bar');
40 isa_ok($baz, 'Foo');
41
42 is($baz->foo(), 'Foo::foo', '... got the right value from &foo');
43 is($baz->bar(), 'Baz::bar -> Bar::bar -> Foo::bar', '... got the right value from &bar');
44 is($baz->baz(), 'Baz::baz -> Foo::baz', '... got the right value from &baz');
45
46 my $bar = Bar->new();
47 isa_ok($bar, 'Bar');
48 isa_ok($bar, 'Foo');
49
50 is($bar->foo(), 'Foo::foo', '... got the right value from &foo');
51 is($bar->bar(), 'Bar::bar -> Foo::bar', '... got the right value from &bar');
52 is($bar->baz(), 'Foo::baz', '... got the right value from &baz');
53
54 my $foo = Foo->new();
55 isa_ok($foo, 'Foo');
56
57 is($foo->foo(), 'Foo::foo', '... got the right value from &foo');
58 is($foo->bar(), 'Foo::bar', '... got the right value from &bar');
59 is($foo->baz(), 'Foo::baz', '... got the right value from &baz');
60
61 # some error cases
62
63 {
64     package Bling;
65     use Mouse;
66
67     sub bling { 'Bling::bling' }
68
69     package Bling::Bling;
70     use Mouse;
71
72     extends 'Bling';
73
74     sub bling { 'Bling::bling' }
75
76     ::dies_ok {
77         override 'bling' => sub {};
78     } '... cannot override a method which has a local equivalent';
79
80 }
81