next-method
[gitmo/Moose.git] / t / 030_basic_safe_mixin.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 ## Mixin a class without a superclass.
13 {
14     package FooMixin;   
15     use Moose;
16     
17     sub foo { 'FooMixin::foo' }    
18
19     package Foo;
20     use Moose;
21     
22     with 'FooMixin';
23     
24     sub new { (shift)->meta->new_object(@_) }
25 }
26
27 my $foo = Foo->new();
28 isa_ok($foo, 'Foo');
29
30 can_ok($foo, 'foo');
31 is($foo->foo, 'FooMixin::foo', '... got the right value from the mixin method');
32
33 ## Mixin a class who shares a common ancestor
34 {   
35     package Baz;
36     use Moose;
37     extends 'Foo';    
38     
39     sub baz { 'Baz::baz' }      
40
41     package Bar;
42     use Moose;
43     extends 'Foo';
44
45     package Foo::Baz;
46     use Moose;
47     extends 'Foo';    
48         eval { with 'Baz' };
49         ::ok(!$@, '... the classes superclass must extend a subclass of the superclass of the mixins');
50
51 }
52
53 my $foo_baz = Foo::Baz->new();
54 isa_ok($foo_baz, 'Foo::Baz');
55 isa_ok($foo_baz, 'Foo');
56
57 can_ok($foo_baz, 'baz');
58 is($foo_baz->baz(), 'Baz::baz', '... got the right value from the mixin method');
59
60 {
61         package Foo::Bar;
62         use Moose;
63     extends 'Foo', 'Bar';       
64
65     package Foo::Bar::Baz;
66     use Moose;
67     extends 'Foo::Bar';    
68         eval { with 'Baz' };
69         ::ok(!$@, '... the classes superclass must extend a subclass of the superclass of the mixins');
70 }
71
72 my $foo_bar_baz = Foo::Bar::Baz->new();
73 isa_ok($foo_bar_baz, 'Foo::Bar::Baz');
74 isa_ok($foo_bar_baz, 'Foo::Bar');
75 isa_ok($foo_bar_baz, 'Foo');
76 isa_ok($foo_bar_baz, 'Bar');
77
78 can_ok($foo_bar_baz, 'baz');
79 is($foo_bar_baz->baz(), 'Baz::baz', '... got the right value from the mixin method');
80