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};
18 sub foo { 'Foo::foo' }
19 sub bar { 'Foo::bar' }
20 sub baz { 'Foo::baz' }
28 with 'My::Role' => { -alias => { bar => 'role_bar' } };
29 } '... this succeeds';
31 package My::Class::Failure;
35 with 'My::Role' => { -alias => { bar => 'role_bar' } };
36 } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds';
38 sub role_bar { 'FAIL' }
41 ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar role_bar);
44 package My::OtherRole;
48 with 'My::Role' => { -alias => { bar => 'role_bar' } };
49 } '... this succeeds';
51 sub bar { 'My::OtherRole::bar' }
53 package My::OtherRole::Failure;
57 with 'My::Role' => { -alias => { bar => 'role_bar' } };
58 } qr/Cannot create a method alias if a local method of the same name exists/, '... cannot alias to a name that exists';
60 sub role_bar { 'FAIL' }
63 ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
64 ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
65 ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
68 package My::AliasingRole;
72 with 'My::Role' => { -alias => { bar => 'role_bar' } };
73 } '... this succeeds';
76 ok(My::AliasingRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
77 ok(!My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is not required');
83 sub foo { 'Foo::Role::foo' }
88 sub foo { 'Bar::Role::foo' }
93 sub foo { 'Baz::Role::foo' }
95 package My::Foo::Class;
99 with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
100 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' },
102 } '... composed our roles correctly';
104 package My::Foo::Class::Broken;
108 with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
109 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
111 } qr/Due to a method name conflict in roles 'Bar::Role' and 'Foo::Role', the method 'foo_foo' must be implemented or excluded by 'My::Foo::Class::Broken'/,
112 '... composed our roles correctly';
116 my $foo = My::Foo::Class->new;
117 isa_ok($foo, 'My::Foo::Class');
118 can_ok($foo, $_) for qw/foo foo_foo bar_foo/;
119 is($foo->foo, 'Baz::Role::foo', '... got the right method');
120 is($foo->foo_foo, 'Foo::Role::foo', '... got the right method');
121 is($foo->bar_foo, 'Bar::Role::foo', '... got the right method');
125 package My::Foo::Role;
129 with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
130 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' },
132 } '... composed our roles correctly';
135 ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;;
136 ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required');
140 package My::Foo::Role::Other;
144 with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
145 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' },
147 } '... composed our roles correctly';
150 ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method");
151 ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required');
154 package My::Foo::AliasOnly;
158 with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' } },
159 } '... composed our roles correctly';
162 ok(My::Foo::AliasOnly->meta->has_method('foo'), 'we have a foo method');
163 ok(My::Foo::AliasOnly->meta->has_method('foo_foo'), '.. and the aliased foo_foo method');
180 with 'Role::Foo' => {
181 -alias => { x1 => 'foo_x1' },
185 'Compose Role::Foo into Role::Bar with alias and exclude';
192 my $bar = Role::Bar->meta;
193 ok( $bar->has_method($_), "has $_ method" )
194 for qw( x1 y1 foo_x1 );
204 with 'Role::Foo' => {
205 -alias => { x1 => 'foo_x1' },
209 'Compose Role::Foo into Role::Baz with alias and exclude';
213 my $baz = Role::Baz->meta;
214 ok( $baz->has_method($_), "has $_ method" )
216 ok( ! $baz->has_method('y1'), 'Role::Baz has no y1 method' );