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