Missed a few use_ok calls that started warning now that Moose::Role
[gitmo/Moose.git] / t / 030_roles / 002_role.t
CommitLineData
e185c027 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
dfc199d4 6use Test::More tests => 36;
e185c027 7use Test::Exception;
8
38f1204c 9=pod
10
11NOTE:
12
13Should we be testing here that the has & override
14are injecting their methods correctly? In other
15words, should 'has_method' return true for them?
16
17=cut
18
e185c027 19{
20 package FooRole;
e185c027 21 use Moose::Role;
22
23 our $VERSION = '0.01';
24
25 has 'bar' => (is => 'rw', isa => 'Foo');
26 has 'baz' => (is => 'ro');
27
28 sub foo { 'FooRole::foo' }
bdabd620 29 sub boo { 'FooRole::boo' }
0558683c 30
31 before 'boo' => sub { "FooRole::boo:before" };
32
33 after 'boo' => sub { "FooRole::boo:after1" };
34 after 'boo' => sub { "FooRole::boo:after2" };
35
36 around 'boo' => sub { "FooRole::boo:around" };
37
38 override 'bling' => sub { "FooRole::bling:override" };
39 override 'fling' => sub { "FooRole::fling:override" };
40
bdabd620 41 ::dies_ok { extends() } '... extends() is not supported';
0558683c 42 ::dies_ok { augment() } '... augment() is not supported';
43 ::dies_ok { inner() } '... inner() is not supported';
fd75e12b 44
45 no Moose::Role;
e185c027 46}
47
48my $foo_role = FooRole->meta;
49isa_ok($foo_role, 'Moose::Meta::Role');
68efb014 50isa_ok($foo_role, 'Class::MOP::Module');
e185c027 51
52is($foo_role->name, 'FooRole', '... got the right name of FooRole');
53is($foo_role->version, '0.01', '... got the right version of FooRole');
54
55# methods ...
56
57ok($foo_role->has_method('foo'), '... FooRole has the foo method');
093b12c2 58is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
e185c027 59
a7d0cd00 60isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
61
bdabd620 62ok($foo_role->has_method('boo'), '... FooRole has the boo method');
093b12c2 63is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
bdabd620 64
65isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method');
66
e185c027 67is_deeply(
bdabd620 68 [ sort $foo_role->get_method_list() ],
69 [ 'boo', 'foo' ],
e185c027 70 '... got the right method list');
fa476537 71
72ok(FooRole->can('foo'), "locally defined methods are still there");
73ok(!FooRole->can('has'), "sugar was unimported");
74
e185c027 75# attributes ...
76
77is_deeply(
78 [ sort $foo_role->get_attribute_list() ],
79 [ 'bar', 'baz' ],
80 '... got the right attribute list');
81
82ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
83
84is_deeply(
85 $foo_role->get_attribute('bar'),
86 { is => 'rw', isa => 'Foo' },
87 '... got the correct description of the bar attribute');
88
89ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
90
91is_deeply(
92 $foo_role->get_attribute('baz'),
93 { is => 'ro' },
94 '... got the correct description of the baz attribute');
95
0558683c 96# method modifiers
97
98ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
99is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
100 "FooRole::boo:before",
101 '... got the right method back');
102
103is_deeply(
104 [ $foo_role->get_method_modifier_list('before') ],
105 [ 'boo' ],
106 '... got the right list of before method modifiers');
107
108ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
109is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
110 "FooRole::boo:after1",
111 '... got the right method back');
112is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
113 "FooRole::boo:after2",
114 '... got the right method back');
115
116is_deeply(
117 [ $foo_role->get_method_modifier_list('after') ],
118 [ 'boo' ],
119 '... got the right list of after method modifiers');
120
121ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
122is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
123 "FooRole::boo:around",
124 '... got the right method back');
125
126is_deeply(
127 [ $foo_role->get_method_modifier_list('around') ],
128 [ 'boo' ],
129 '... got the right list of around method modifiers');
130
131## overrides
132
133ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
134is($foo_role->get_override_method_modifier('bling')->(),
135 "FooRole::bling:override",
136 '... got the right method back');
137
138ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
139is($foo_role->get_override_method_modifier('fling')->(),
140 "FooRole::fling:override",
141 '... got the right method back');
142
143is_deeply(
144 [ sort $foo_role->get_method_modifier_list('override') ],
145 [ 'bling', 'fling' ],
146 '... got the right list of override method modifiers');
147