Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 026_role_composition_method_mods.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 7;
7 use Test::Exception;
8
9 use Mouse::Meta::Role::Application::RoleSummation;
10 use Mouse::Meta::Role::Composite;
11
12 {
13     package Role::Foo;
14     use Mouse::Role;
15
16     before foo => sub { 'Role::Foo::foo' };
17     around foo => sub { 'Role::Foo::foo' };
18     after  foo => sub { 'Role::Foo::foo' };
19     around baz => sub { [ 'Role::Foo', @{shift->(@_)} ] };
20
21     package Role::Bar;
22     use Mouse::Role;
23
24     before bar => sub { 'Role::Bar::bar' };
25     around bar => sub { 'Role::Bar::bar' };
26     after  bar => sub { 'Role::Bar::bar' };
27
28     package Role::Baz;
29     use Mouse::Role;
30
31     with 'Role::Foo';
32     around baz => sub { [ 'Role::Baz', @{shift->(@_)} ] };
33
34 }
35
36 {
37   package Class::FooBar;
38   use Mouse;
39
40   with 'Role::Baz';
41   sub foo { 'placeholder' }
42   sub baz { ['Class::FooBar'] }
43 }
44
45 #test modifier call order
46 {
47     is_deeply(
48         Class::FooBar->baz,
49         ['Role::Baz','Role::Foo','Class::FooBar']
50     );
51 }
52
53 # test simple overrides
54 {
55     my $c = Mouse::Meta::Role::Composite->new(
56         roles => [
57             Role::Foo->meta,
58             Role::Bar->meta,
59         ]
60     );
61     isa_ok($c, 'Mouse::Meta::Role::Composite');
62
63     is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
64
65     lives_ok {
66         Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
67     } '... this succeeds as expected';
68
69     is_deeply(
70         [ sort $c->get_method_modifier_list('before') ],
71         [ 'bar', 'foo' ],
72         '... got the right list of methods'
73     );
74
75     is_deeply(
76         [ sort $c->get_method_modifier_list('after') ],
77         [ 'bar', 'foo' ],
78         '... got the right list of methods'
79     );
80
81     is_deeply(
82         [ sort $c->get_method_modifier_list('around') ],
83         [ 'bar', 'baz', 'foo' ],
84         '... got the right list of methods'
85     );
86 }