6 use Test::More tests => 36;
13 Should we be testing here that the has & override
14 are injecting their methods correctly? In other
15 words, should 'has_method' return true for them?
23 our $VERSION = '0.01';
25 has 'bar' => (is => 'rw', isa => 'Foo');
26 has 'baz' => (is => 'ro');
28 sub foo { 'FooRole::foo' }
29 sub boo { 'FooRole::boo' }
31 before 'boo' => sub { "FooRole::boo:before" };
33 after 'boo' => sub { "FooRole::boo:after1" };
34 after 'boo' => sub { "FooRole::boo:after2" };
36 around 'boo' => sub { "FooRole::boo:around" };
38 override 'bling' => sub { "FooRole::bling:override" };
39 override 'fling' => sub { "FooRole::fling:override" };
41 ::dies_ok { extends() } '... extends() is not supported';
42 ::dies_ok { augment() } '... augment() is not supported';
43 ::dies_ok { inner() } '... inner() is not supported';
48 my $foo_role = FooRole->meta;
49 isa_ok($foo_role, 'Moose::Meta::Role');
50 isa_ok($foo_role, 'Class::MOP::Module');
52 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
53 is($foo_role->version, '0.01', '... got the right version of FooRole');
57 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
58 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
60 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
62 ok($foo_role->has_method('boo'), '... FooRole has the boo method');
63 is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
65 isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method');
68 [ sort $foo_role->get_method_list() ],
70 '... got the right method list');
72 ok(FooRole->can('foo'), "locally defined methods are still there");
73 ok(!FooRole->can('has'), "sugar was unimported");
78 [ sort $foo_role->get_attribute_list() ],
80 '... got the right attribute list');
82 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
85 $foo_role->get_attribute('bar'),
86 { is => 'rw', isa => 'Foo' },
87 '... got the correct description of the bar attribute');
89 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
92 $foo_role->get_attribute('baz'),
94 '... got the correct description of the baz attribute');
98 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
99 is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
100 "FooRole::boo:before",
101 '... got the right method back');
104 [ $foo_role->get_method_modifier_list('before') ],
106 '... got the right list of before method modifiers');
108 ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
109 is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
110 "FooRole::boo:after1",
111 '... got the right method back');
112 is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
113 "FooRole::boo:after2",
114 '... got the right method back');
117 [ $foo_role->get_method_modifier_list('after') ],
119 '... got the right list of after method modifiers');
121 ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
122 is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
123 "FooRole::boo:around",
124 '... got the right method back');
127 [ $foo_role->get_method_modifier_list('around') ],
129 '... got the right list of around method modifiers');
133 ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
134 is($foo_role->get_override_method_modifier('bling')->(),
135 "FooRole::bling:override",
136 '... got the right method back');
138 ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
139 is($foo_role->get_override_method_modifier('fling')->(),
140 "FooRole::fling:override",
141 '... got the right method back');
144 [ sort $foo_role->get_method_modifier_list('override') ],
145 [ 'bling', 'fling' ],
146 '... got the right list of override method modifiers');