6 use Test::More tests => 20;
17 sub foo { 'Foo::foo' }
18 sub bar { 'Foo::bar' }
19 sub baz { 'Foo::baz' }
24 with 'My::Role' => { excludes => 'bar' };
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');
31 package My::OtherRole;
34 with 'My::Role' => { excludes => 'foo' };
36 sub foo { 'My::OtherRole::foo' }
37 sub bar { 'My::OtherRole::bar' }
40 ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz);
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');
49 sub foo { 'Foo::Role::foo' }
54 sub foo { 'Bar::Role::foo' }
59 sub foo { 'Baz::Role::foo' }
61 package My::Foo::Class;
65 with 'Foo::Role' => { excludes => 'foo' },
66 'Bar::Role' => { excludes => 'foo' },
68 } '... composed our roles correctly';
70 package My::Foo::Class::Broken;
75 'Bar::Role' => { excludes => 'foo' },
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';
82 my $foo = My::Foo::Class->new;
83 isa_ok($foo, 'My::Foo::Class');
85 is($foo->foo, 'Baz::Role::foo', '... got the right method');
89 package My::Foo::Role;
93 with 'Foo::Role' => { excludes => 'foo' },
94 'Bar::Role' => { excludes => 'foo' },
96 } '... composed our roles correctly';
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');
103 package My::Foo::Role::Other;
108 'Bar::Role' => { excludes => 'foo' },
110 } '... composed our roles correctly';
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');