6 use Test::More tests => 40;
10 use Test::Mouse; # Mouse::Meta::Module->version
16 Should we be testing here that the has & override
17 are injecting their methods correctly? In other
18 words, should 'has_method' return true for them?
26 our $VERSION = '0.01';
28 has 'bar' => (is => 'rw', isa => 'Foo');
29 has 'baz' => (is => 'ro');
31 sub foo { 'FooRole::foo' }
32 sub boo { 'FooRole::boo' }
34 before 'boo' => sub { "FooRole::boo:before" };
36 after 'boo' => sub { "FooRole::boo:after1" };
37 after 'boo' => sub { "FooRole::boo:after2" };
39 around 'boo' => sub { "FooRole::boo:around" };
41 override 'bling' => sub { "FooRole::bling:override" };
42 override 'fling' => sub { "FooRole::fling:override" };
44 ::dies_ok { extends() } '... extends() is not supported';
45 ::dies_ok { augment() } '... augment() is not supported';
46 ::dies_ok { inner() } '... inner() is not supported';
51 my $foo_role = FooRole->meta;
52 isa_ok($foo_role, 'Mouse::Meta::Role');
53 #isa_ok($foo_role, 'Class::MOP::Module');
55 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
56 is($foo_role->version, '0.01', '... got the right version of FooRole');
61 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
62 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
64 isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
66 ok($foo_role->has_method('boo'), '... FooRole has the boo method');
67 is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
69 isa_ok($foo_role->get_method('boo'), 'Mouse::Meta::Role::Method');
72 [ sort $foo_role->get_method_list() ],
73 [ 'boo', 'foo', 'meta' ],
74 '... got the right method list');
76 ok(FooRole->can('foo'), "locally defined methods are still there");
77 ok(!FooRole->can('has'), "sugar was unimported");
82 [ sort $foo_role->get_attribute_list() ],
84 '... got the right attribute list');
86 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
88 my $bar_attr = $foo_role->get_attribute('bar');
89 is($bar_attr->{is}, 'rw',
90 'bar attribute is rw');
91 is($bar_attr->{isa}, 'Foo',
92 'bar attribute isa Foo');
94 local $TODO = 'definition_context is not yet implemented';
95 is(ref($bar_attr->{definition_context}), 'HASH',
96 'bar\'s definition context is a hash');
97 is($bar_attr->{definition_context}->{package}, 'FooRole',
98 'bar was defined in FooRole');
101 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
103 my $baz_attr = $foo_role->get_attribute('baz');
104 is($baz_attr->{is}, 'ro',
105 'baz attribute is ro');
108 local $TODO = 'definition_context is not yet implemented';
109 is(ref($baz_attr->{definition_context}), 'HASH',
110 'bar\'s definition context is a hash');
111 is($baz_attr->{definition_context}->{package}, 'FooRole',
112 'baz was defined in FooRole');
117 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
118 is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
119 "FooRole::boo:before",
120 '... got the right method back');
123 [ $foo_role->get_method_modifier_list('before') ],
125 '... got the right list of before method modifiers');
127 ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
128 is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
129 "FooRole::boo:after1",
130 '... got the right method back');
131 is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
132 "FooRole::boo:after2",
133 '... got the right method back');
136 [ $foo_role->get_method_modifier_list('after') ],
138 '... got the right list of after method modifiers');
140 ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
141 is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
142 "FooRole::boo:around",
143 '... got the right method back');
146 [ $foo_role->get_method_modifier_list('around') ],
148 '... got the right list of around method modifiers');
152 ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
153 is($foo_role->get_override_method_modifier('bling')->(),
154 "FooRole::bling:override",
155 '... got the right method back');
157 ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
158 is($foo_role->get_override_method_modifier('fling')->(),
159 "FooRole::fling:override",
160 '... got the right method back');
163 [ sort $foo_role->get_method_modifier_list('override') ],
164 [ 'bling', 'fling' ],
165 '... got the right list of override method modifiers');