Commit | Line | Data |
67199842 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More tests => 19; |
7 | use Test::Exception; |
8 | |
9 | |
10 | |
11 | { |
12 | package My::Role; |
13 | use Mouse::Role; |
14 | |
15 | sub foo { 'Foo::foo' } |
16 | sub bar { 'Foo::bar' } |
17 | sub baz { 'Foo::baz' } |
18 | |
19 | package My::Class; |
20 | use Mouse; |
21 | |
22 | with 'My::Role' => { excludes => 'bar' }; |
23 | } |
24 | |
25 | ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz); |
26 | ok(!My::Class->meta->has_method('bar'), '... but we excluded bar'); |
27 | |
28 | { |
29 | package My::OtherRole; |
30 | use Mouse::Role; |
31 | |
32 | with 'My::Role' => { excludes => 'foo' }; |
33 | |
34 | sub foo { 'My::OtherRole::foo' } |
35 | sub bar { 'My::OtherRole::bar' } |
36 | } |
37 | |
38 | ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz); |
39 | |
40 | ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required'); |
41 | ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required'); |
42 | |
43 | { |
44 | package Foo::Role; |
45 | use Mouse::Role; |
c2d7552a |
46 | |
67199842 |
47 | sub foo { 'Foo::Role::foo' } |
c2d7552a |
48 | |
67199842 |
49 | package Bar::Role; |
50 | use Mouse::Role; |
c2d7552a |
51 | |
52 | sub foo { 'Bar::Role::foo' } |
67199842 |
53 | |
54 | package Baz::Role; |
55 | use Mouse::Role; |
c2d7552a |
56 | |
57 | sub foo { 'Baz::Role::foo' } |
58 | |
67199842 |
59 | package My::Foo::Class; |
60 | use Mouse; |
c2d7552a |
61 | |
67199842 |
62 | ::lives_ok { |
63 | with 'Foo::Role' => { excludes => 'foo' }, |
c2d7552a |
64 | 'Bar::Role' => { excludes => 'foo' }, |
67199842 |
65 | 'Baz::Role'; |
66 | } '... composed our roles correctly'; |
c2d7552a |
67 | |
67199842 |
68 | package My::Foo::Class::Broken; |
69 | use Mouse; |
c2d7552a |
70 | |
67199842 |
71 | ::throws_ok { |
72 | with 'Foo::Role', |
c2d7552a |
73 | 'Bar::Role' => { excludes => 'foo' }, |
67199842 |
74 | 'Baz::Role'; |
c2d7552a |
75 | } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, |
76 | '... composed our roles correctly'; |
67199842 |
77 | } |
78 | |
79 | { |
80 | my $foo = My::Foo::Class->new; |
81 | isa_ok($foo, 'My::Foo::Class'); |
82 | can_ok($foo, 'foo'); |
83 | is($foo->foo, 'Baz::Role::foo', '... got the right method'); |
84 | } |
85 | |
86 | { |
87 | package My::Foo::Role; |
88 | use Mouse::Role; |
89 | |
90 | ::lives_ok { |
91 | with 'Foo::Role' => { excludes => 'foo' }, |
c2d7552a |
92 | 'Bar::Role' => { excludes => 'foo' }, |
67199842 |
93 | 'Baz::Role'; |
94 | } '... composed our roles correctly'; |
95 | } |
96 | |
97 | ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method"); |
98 | ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required'); |
99 | |
100 | { |
101 | package My::Foo::Role::Other; |
102 | use Mouse::Role; |
103 | |
104 | ::lives_ok { |
105 | with 'Foo::Role', |
c2d7552a |
106 | 'Bar::Role' => { excludes => 'foo' }, |
67199842 |
107 | 'Baz::Role'; |
108 | } '... composed our roles correctly'; |
109 | } |
110 | |
111 | ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method"); |
112 | ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required'); |
113 | |
114 | |
115 | |