6 use Test::More tests => 40;
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, 'Mouse::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');
58 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
59 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
61 isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
63 ok($foo_role->has_method('boo'), '... FooRole has the boo method');
64 is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method');
66 isa_ok($foo_role->get_method('boo'), 'Mouse::Meta::Role::Method');
69 [ sort $foo_role->get_method_list() ],
70 [ 'boo', 'foo', 'meta' ],
71 '... got the right method list');
73 ok(FooRole->can('foo'), "locally defined methods are still there");
74 ok(!FooRole->can('has'), "sugar was unimported");
79 [ sort $foo_role->get_attribute_list() ],
81 '... got the right attribute list');
83 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
86 local $TODO = 'definition_context is not yet implemented';
87 my $bar_attr = $foo_role->get_attribute('bar');
88 is($bar_attr->{is}, 'rw',
89 'bar attribute is rw');
90 is($bar_attr->{isa}, 'Foo',
91 'bar attribute isa Foo');
92 is(ref($bar_attr->{definition_context}), 'HASH',
93 'bar\'s definition context is a hash');
94 is($bar_attr->{definition_context}->{package}, 'FooRole',
95 'bar was defined in FooRole');
97 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
99 my $baz_attr = $foo_role->get_attribute('baz');
100 is($baz_attr->{is}, 'ro',
101 'baz attribute is ro');
102 is(ref($baz_attr->{definition_context}), 'HASH',
103 'bar\'s definition context is a hash');
104 is($baz_attr->{definition_context}->{package}, 'FooRole',
105 'baz was defined in FooRole');
106 } # end of TODO (definition_context)
110 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
111 is(($foo_role->get_before_method_modifiers('boo'))[0]->(),
112 "FooRole::boo:before",
113 '... got the right method back');
116 [ $foo_role->get_method_modifier_list('before') ],
118 '... got the right list of before method modifiers');
120 ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
121 is(($foo_role->get_after_method_modifiers('boo'))[0]->(),
122 "FooRole::boo:after1",
123 '... got the right method back');
124 is(($foo_role->get_after_method_modifiers('boo'))[1]->(),
125 "FooRole::boo:after2",
126 '... got the right method back');
129 [ $foo_role->get_method_modifier_list('after') ],
131 '... got the right list of after method modifiers');
133 ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
134 is(($foo_role->get_around_method_modifiers('boo'))[0]->(),
135 "FooRole::boo:around",
136 '... got the right method back');
139 [ $foo_role->get_method_modifier_list('around') ],
141 '... got the right list of around method modifiers');
145 ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
146 is($foo_role->get_override_method_modifier('bling')->(),
147 "FooRole::bling:override",
148 '... got the right method back');
150 ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
151 is($foo_role->get_override_method_modifier('fling')->(),
152 "FooRole::fling:override",
153 '... got the right method back');
156 [ sort $foo_role->get_method_modifier_list('override') ],
157 [ 'bling', 'fling' ],
158 '... got the right list of override method modifiers');