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