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