Merge 'Moose-moosex_compile_support' into 'trunk'
[gitmo/Moose.git] / t / 030_roles / 013_method_aliasing_during_composition.t
CommitLineData
3e19778d 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7use Test::Exception;
8
9BEGIN {
10 use_ok('Moose');
11}
12
13{
14 package My::Role;
15 use Moose::Role;
16
17 sub foo { 'Foo::foo' }
18 sub bar { 'Foo::bar' }
19 sub baz { 'Foo::baz' }
20
21 requires 'role_bar';
22
23 package My::Class;
24 use Moose;
25
26 ::lives_ok {
27 with 'My::Role' => { alias => { bar => 'role_bar' } };
28 } '... this succeeds';
43a41ede 29
30 package My::Class::Failure;
31 use Moose;
32
33 ::throws_ok {
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';
36
37 sub role_bar { 'FAIL' }
3e19778d 38}
39
43a41ede 40ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar role_bar);
3e19778d 41
42{
43 package My::OtherRole;
44 use Moose::Role;
45
46 ::lives_ok {
47 with 'My::Role' => { alias => { bar => 'role_bar' } };
48 } '... this succeeds';
49
50 sub bar { 'My::OtherRole::bar' }
43a41ede 51
52 package My::OtherRole::Failure;
53 use Moose::Role;
54
55 ::throws_ok {
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';
58
59 sub role_bar { 'FAIL' }
3e19778d 60}
61
43a41ede 62ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz role_bar);
63ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required');
3e19778d 64ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required');
65
66
67
68
69