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