Commit | Line | Data |
c4538447 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
7ff56534 |
6 | use Test::More tests => 19; |
c4538447 |
7 | use Test::Exception; |
8 | |
7ff56534 |
9 | |
c4538447 |
10 | |
11 | { |
12 | package My::Role; |
13 | use Moose::Role; |
14 | |
15 | sub foo { 'Foo::foo' } |
16 | sub bar { 'Foo::bar' } |
17 | sub baz { 'Foo::baz' } |
18 | |
19 | package My::Class; |
20 | use Moose; |
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 Moose::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 | |
28412c0b |
43 | { |
44 | package Foo::Role; |
45 | use Moose::Role; |
d03bd989 |
46 | |
28412c0b |
47 | sub foo { 'Foo::Role::foo' } |
d03bd989 |
48 | |
28412c0b |
49 | package Bar::Role; |
50 | use Moose::Role; |
d03bd989 |
51 | |
52 | sub foo { 'Bar::Role::foo' } |
28412c0b |
53 | |
54 | package Baz::Role; |
55 | use Moose::Role; |
d03bd989 |
56 | |
57 | sub foo { 'Baz::Role::foo' } |
58 | |
28412c0b |
59 | package My::Foo::Class; |
60 | use Moose; |
d03bd989 |
61 | |
28412c0b |
62 | ::lives_ok { |
63 | with 'Foo::Role' => { excludes => 'foo' }, |
d03bd989 |
64 | 'Bar::Role' => { excludes => 'foo' }, |
28412c0b |
65 | 'Baz::Role'; |
66 | } '... composed our roles correctly'; |
d03bd989 |
67 | |
28412c0b |
68 | package My::Foo::Class::Broken; |
69 | use Moose; |
d03bd989 |
70 | |
28412c0b |
71 | ::throws_ok { |
72 | with 'Foo::Role', |
d03bd989 |
73 | 'Bar::Role' => { excludes => 'foo' }, |
28412c0b |
74 | 'Baz::Role'; |
79886df7 |
75 | } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented by 'My::Foo::Class::Broken'/, |
d03bd989 |
76 | '... composed our roles correctly'; |
28412c0b |
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 Moose::Role; |
89 | |
90 | ::lives_ok { |
91 | with 'Foo::Role' => { excludes => 'foo' }, |
d03bd989 |
92 | 'Bar::Role' => { excludes => 'foo' }, |
28412c0b |
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 Moose::Role; |
103 | |
104 | ::lives_ok { |
105 | with 'Foo::Role', |
d03bd989 |
106 | 'Bar::Role' => { excludes => 'foo' }, |
28412c0b |
107 | 'Baz::Role'; |
108 | } '... composed our roles correctly'; |
109 | } |
c4538447 |
110 | |
28412c0b |
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'); |
c4538447 |
113 | |
114 | |
115 | |