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