6 use Test::More tests => 36;
17 sub foo { 'Foo::foo' }
18 sub bar { 'Foo::bar' }
19 sub baz { 'Foo::baz' }
27 with 'My::Role' => { alias => { bar => 'role_bar' } };
28 } '... this succeeds';
30 package My::Class::Failure;
34 with 'My::Role' => { alias => { bar => 'role_bar' } };
35 } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
37 sub role_bar { 'FAIL' }
40 ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar role_bar);
43 package My::OtherRole;
47 with 'My::Role' => { alias => { bar => 'role_bar' } };
48 } '... this succeeds';
50 sub bar { 'My::OtherRole::bar' }
52 package My::OtherRole::Failure;
56 with 'My::Role' => { alias => { bar => 'role_bar' } };
57 } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
59 sub role_bar { 'FAIL' }
62 ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
63 ok(!My::OtherRole->meta->requires_method('bar'), '... and the &bar method is not required');
64 ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
67 package My::AliasingRole;
71 with 'My::Role' => { alias => { bar => 'role_bar' } };
72 } '... this succeeds';
75 ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
76 ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is required');
82 sub foo { 'Foo::Role::foo' }
87 sub foo { 'Bar::Role::foo' }
92 sub foo { 'Baz::Role::foo' }
94 package My::Foo::Class;
98 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
99 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
101 } '... composed our roles correctly';
103 package My::Foo::Class::Broken;
107 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
108 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
110 } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/,
111 '... composed our roles correctly';
115 my $foo = My::Foo::Class->new;
116 isa_ok($foo, 'My::Foo::Class');
117 can_ok($foo, $_) for qw/foo foo_foo bar_foo/;
118 is($foo->foo, 'Baz::Role::foo', '... got the right method');
119 is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');
120 is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');
124 package My::Foo::Role;
128 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
129 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
131 } '... composed our roles correctly';
134 ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;;
135 ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
139 package My::Foo::Role::Other;
143 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
144 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
146 } '... composed our roles correctly';
149 ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
150 ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');