DEATH TO ALL zionist ELLIPSES
[gitmo/Moose.git] / t / 010_basics / 006_override_and_foreign_classes.t
CommitLineData
05d9eaf6 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
7ff56534 6use Test::More tests => 15;
7
05d9eaf6 8
05d9eaf6 9
10=pod
11
12This just tests the interaction of override/super
d03bd989 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
05d9eaf6 16super method.
17
d03bd989 18This may end up being a sensitive issue for some
19non-Moose classes, but in 99% of the cases it
20should be just fine.
05d9eaf6 21
22=cut
23
24{
25 package Foo;
26 use strict;
27 use warnings;
d03bd989 28
05d9eaf6 29 sub new { bless {} => shift() }
d03bd989 30
05d9eaf6 31 sub foo { 'Foo::foo' }
d03bd989 32 sub bar { 'Foo::bar' }
05d9eaf6 33 sub baz { 'Foo::baz' }
d03bd989 34
05d9eaf6 35 package Bar;
05d9eaf6 36 use Moose;
d03bd989 37
05d9eaf6 38 extends 'Foo';
d03bd989 39
40 override bar => sub { 'Bar::bar -> ' . super() };
41
05d9eaf6 42 package Baz;
05d9eaf6 43 use Moose;
d03bd989 44
05d9eaf6 45 extends 'Bar';
d03bd989 46
47 override bar => sub { 'Baz::bar -> ' . super() };
48 override baz => sub { 'Baz::baz -> ' . super() };
05d9eaf6 49}
50
51my $baz = Baz->new();
52isa_ok($baz, 'Baz');
53isa_ok($baz, 'Bar');
54isa_ok($baz, 'Foo');
55
1808c2da 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');
05d9eaf6 59
60my $bar = Bar->new();
61isa_ok($bar, 'Bar');
62isa_ok($bar, 'Foo');
63
1808c2da 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');
05d9eaf6 67
68my $foo = Foo->new();
69isa_ok($foo, 'Foo');
70
1808c2da 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');