Mouse::Role improved
[gitmo/Mouse.git] / t / 030_roles / failing / 026_role_composition_method_mods.t
CommitLineData
67199842 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More tests => 7;
7use Test::Exception;
8
9use Mouse::Meta::Role::Application::RoleSummation;
10use Mouse::Meta::Role::Composite;
11
12{
13 package Role::Foo;
14 use Mouse::Role;
15
16 before foo => sub { 'Role::Foo::foo' };
6cfa1e5e 17 around foo => sub { 'Role::Foo::foo' };
18 after foo => sub { 'Role::Foo::foo' };
67199842 19 around baz => sub { [ 'Role::Foo', @{shift->(@_)} ] };
20
21 package Role::Bar;
22 use Mouse::Role;
23
24 before bar => sub { 'Role::Bar::bar' };
6cfa1e5e 25 around bar => sub { 'Role::Bar::bar' };
26 after bar => sub { 'Role::Bar::bar' };
67199842 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
6cfa1e5e 63 is($c->name, 'Role::Foo|Role::Bar', '... got the composite role name');
67199842 64
65 lives_ok {
66 Mouse::Meta::Role::Application::RoleSummation->new->apply($c);
6cfa1e5e 67 } '... this succeeds as expected';
67199842 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'
6cfa1e5e 79 );
67199842 80
81 is_deeply(
82 [ sort $c->get_method_modifier_list('around') ],
83 [ 'bar', 'baz', 'foo' ],
84 '... got the right list of methods'
6cfa1e5e 85 );
67199842 86}