6 use Test::More tests => 19;
15 sub foo { 'Foo::foo' }
16 sub bar { 'Foo::bar' }
17 sub baz { 'Foo::baz' }
22 with 'My::Role' => { -excludes => 'bar' };
25 ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz);
26 ok(!My::Class->meta->has_method('bar'), '... but we excluded bar');
29 package My::OtherRole;
32 with 'My::Role' => { -excludes => 'foo' };
34 sub foo { 'My::OtherRole::foo' }
35 sub bar { 'My::OtherRole::bar' }
38 ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar baz);
40 ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required');
41 ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
42 use Data::Dumper; print Dumper(My::OtherRole->meta->{required_methods});
47 sub foo { 'Foo::Role::foo' }
52 sub foo { 'Bar::Role::foo' }
57 sub foo { 'Baz::Role::foo' }
59 package My::Foo::Class;
63 with 'Foo::Role' => { -excludes => 'foo' },
64 'Bar::Role' => { -excludes => 'foo' },
66 } '... composed our roles correctly';
68 package My::Foo::Class::Broken;
73 'Bar::Role' => { -excludes => 'foo' },
75 } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/,
76 '... composed our roles correctly';
80 my $foo = My::Foo::Class->new;
81 isa_ok($foo, 'My::Foo::Class');
83 is($foo->foo, 'Baz::Role::foo', '... got the right method');
87 package My::Foo::Role;
91 with 'Foo::Role' => { -excludes => 'foo' },
92 'Bar::Role' => { -excludes => 'foo' },
94 } '... composed our roles correctly';
97 ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method");
98 ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
101 package My::Foo::Role::Other;
106 'Bar::Role' => { -excludes => 'foo' },
108 } '... composed our roles correctly';
111 ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method");
112 ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required');