6 use Test::More tests => 31;
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 required');
64 ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
70 sub foo { 'Foo::Role::foo' }
75 sub foo { 'Bar::Role::foo' }
80 sub foo { 'Baz::Role::foo' }
82 package My::Foo::Class;
86 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
87 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
89 } '... composed our roles correctly';
91 package My::Foo::Class::Broken;
95 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
96 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
98 } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/,
99 '... composed our roles correctly';
103 my $foo = My::Foo::Class->new;
104 isa_ok($foo, 'My::Foo::Class');
105 can_ok($foo, $_) for qw/foo foo_foo bar_foo/;
106 is($foo->foo, 'Baz::Role::foo', '... got the right method');
107 is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');
108 is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');
112 package My::Foo::Role;
116 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
117 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' },
119 } '... composed our roles correctly';
122 ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;;
123 ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
127 package My::Foo::Role::Other;
131 with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
132 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' },
134 } '... composed our roles correctly';
137 ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
138 ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');