2 # This is automatically generated by author/import-moose-test.pl.
3 # DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4 use t::lib::MooseCompat;
10 $TODO = q{Mouse is not yet completed};
15 # test no conflicts here
19 sub bar { 'Role::A::bar' }
24 sub xxy { 'Role::B::xxy' }
30 with qw(Role::A Role::B); # no conflict here
33 sub foo { 'Role::C::foo' }
34 sub zot { 'Role::C::zot' }
43 sub zot { 'Class::A::zot' }
46 can_ok( Class::A->new, qw(foo bar xxy zot) );
48 is( Class::A->new->foo, "Role::C::foo", "... got the right foo method" );
49 is( Class::A->new->zot, "Class::A::zot", "... got the right zot method" );
50 is( Class::A->new->bar, "Role::A::bar", "... got the right bar method" );
51 is( Class::A->new->xxy, "Role::B::xxy", "... got the right xxy method" );
54 # check that when a role is added to another role
55 # and they conflict and the method they conflict
56 # with is then required.
58 package Role::A::Conflict;
63 sub bar { 'Role::A::Conflict::bar' }
65 package Class::A::Conflict;
69 with 'Role::A::Conflict';
70 } qr/Due to a method name conflict in roles 'Role::A' and 'Role::A::Conflict', the method 'bar' must be implemented or excluded by 'Class::A::Conflict'/, '... did not fufill the requirement of &bar method';
72 package Class::A::Resolved;
76 with 'Role::A::Conflict';
77 } '... did fufill the requirement of &bar method';
79 sub bar { 'Class::A::Resolved::bar' }
82 ok(Role::A::Conflict->meta->requires_method('bar'), '... Role::A::Conflict created the bar requirement');
84 can_ok( Class::A::Resolved->new, qw(bar) );
86 is( Class::A::Resolved->new->bar, 'Class::A::Resolved::bar', "... got the right bar method" );
89 # check that when two roles are composed, they conflict
90 # but the composing role can resolve that conflict
95 sub foo { 'Role::D::foo' }
96 sub bar { 'Role::D::bar' }
101 sub foo { 'Role::E::foo' }
102 sub xxy { 'Role::E::xxy' }
108 with qw(Role::D Role::E); # conflict between 'foo's here
109 } "define role Role::F";
111 sub foo { 'Role::F::foo' }
112 sub zot { 'Role::F::zot' }
119 } "define class Class::B";
121 sub zot { 'Class::B::zot' }
124 can_ok( Class::B->new, qw(foo bar xxy zot) );
126 is( Class::B->new->foo, "Role::F::foo", "... got the &foo method okay" );
127 is( Class::B->new->zot, "Class::B::zot", "... got the &zot method okay" );
128 is( Class::B->new->bar, "Role::D::bar", "... got the &bar method okay" );
129 is( Class::B->new->xxy, "Role::E::xxy", "... got the &xxy method okay" );
131 ok(!Role::F->meta->requires_method('foo'), '... Role::F fufilled the &foo requirement');
134 # check that a conflict can be resolved
135 # by a role, but also new ones can be
136 # created just as easily ...
138 package Role::D::And::E::Conflict;
142 with qw(Role::D Role::E); # conflict between 'foo's here
143 } "... define role Role::D::And::E::Conflict";
145 sub foo { 'Role::D::And::E::Conflict::foo' } # this overrides ...
148 sub xxy { 'Role::D::And::E::Conflict::xxy' }
149 sub bar { 'Role::D::And::E::Conflict::bar' }
153 ok(!Role::D::And::E::Conflict->meta->requires_method('foo'), '... Role::D::And::E::Conflict fufilled the &foo requirement');
154 ok(Role::D::And::E::Conflict->meta->requires_method('xxy'), '... Role::D::And::E::Conflict adds the &xxy requirement');
155 ok(Role::D::And::E::Conflict->meta->requires_method('bar'), '... Role::D::And::E::Conflict adds the &bar requirement');
158 # conflict propagation
163 sub foo { 'Role::H::foo' }
164 sub bar { 'Role::H::bar' }
169 sub foo { 'Role::J::foo' }
170 sub xxy { 'Role::J::xxy' }
176 with qw(Role::J Role::H); # conflict between 'foo's here
177 } "define role Role::I";
179 sub zot { 'Role::I::zot' }
180 sub zzy { 'Role::I::zzy' }
187 } qr/Due to a method name conflict in roles 'Role::H' and 'Role::J', the method 'foo' must be implemented or excluded by 'Class::C'/, "defining class Class::C fails";
189 sub zot { 'Class::C::zot' }
196 } "resolved with method";
198 sub foo { 'Class::E::foo' }
199 sub zot { 'Class::E::zot' }
202 can_ok( Class::E->new, qw(foo bar xxy zot) );
204 is( Class::E->new->foo, "Class::E::foo", "... got the right &foo method" );
205 is( Class::E->new->zot, "Class::E::zot", "... got the right &zot method" );
206 is( Class::E->new->bar, "Role::H::bar", "... got the right &bar method" );
207 is( Class::E->new->xxy, "Role::J::xxy", "... got the right &xxy method" );
209 ok(Role::I->meta->requires_method('foo'), '... Role::I still have the &foo requirement');
216 has foo => ( default => __PACKAGE__ . "::foo", is => "rw" );
218 sub zot { 'Class::D::zot' }
222 } "resolved with attr";
224 can_ok( Class::D->new, qw(foo bar xxy zot) );
225 is( eval { Class::D->new->bar }, "Role::H::bar", "bar" );
226 is( eval { Class::D->new->zzy }, "Role::I::zzy", "zzy" );
228 is( eval { Class::D->new->foo }, "Class::D::foo", "foo" );
229 is( eval { Class::D->new->zot }, "Class::D::zot", "zot" );