foo
[gitmo/Moose.git] / t / 047_role_conflict_edge_cases.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 14;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Moose');
11     use_ok('Moose::Role');    
12 }
13
14 =pod
15
16 Check for repeated inheritence causing 
17 a method conflict (which is not really 
18 a conflict)
19
20 =cut
21
22 {
23     package Role::Base;
24     use Moose::Role;
25     
26     sub foo { 'Role::Base::foo' }
27     
28     package Role::Derived1;
29     use Moose::Role;  
30     
31     with 'Role::Base';
32     
33     package Role::Derived2;
34     use Moose::Role; 
35
36     with 'Role::Base';
37     
38     package My::Test::Class1;
39     use Moose;      
40     
41     ::lives_ok {
42         with 'Role::Derived1', 'Role::Derived2';   
43     } '... roles composed okay (no conflicts)';
44 }
45
46 ok(Role::Base->meta->has_method('foo'), '... have the method foo as expected');
47 ok(Role::Derived1->meta->has_method('foo'), '... have the method foo as expected');
48 ok(Role::Derived2->meta->has_method('foo'), '... have the method foo as expected');
49 ok(My::Test::Class1->meta->has_method('foo'), '... have the method foo as expected');
50
51 is(My::Test::Class1->foo, 'Role::Base::foo', '... got the right value from method');
52
53 =pod
54
55 Check for repeated inheritence causing 
56 a attr conflict (which is not really 
57 a conflict)
58
59 =cut
60
61 {
62     package Role::Base4;
63     use Moose::Role;
64     
65     has 'foo' => (is => 'ro', default => 'Role::Base::foo');
66     
67     package Role::Derived7;
68     use Moose::Role;  
69     
70     with 'Role::Base4';
71     
72     package Role::Derived8;
73     use Moose::Role; 
74
75     with 'Role::Base4';
76     
77     package My::Test::Class4;
78     use Moose;      
79     
80     ::lives_ok {
81         with 'Role::Derived7', 'Role::Derived8';   
82     } '... roles composed okay (no conflicts)';
83 }
84
85 ok(Role::Base4->meta->has_attribute('foo'), '... have the attribute foo as expected');
86 ok(Role::Derived7->meta->has_attribute('foo'), '... have the attribute foo as expected');
87 ok(Role::Derived8->meta->has_attribute('foo'), '... have the attribute foo as expected');
88 ok(My::Test::Class4->meta->has_attribute('foo'), '... have the attribute foo as expected');
89
90 is(My::Test::Class4->new->foo, 'Role::Base::foo', '... got the right value from method');