6 use Test::More tests => 27;
14 our $VERSION = '0.01';
16 sub foo { 'FooRole::foo' }
19 my $foo_role = Moose::Meta::Role->initialize('FooRole');
20 isa_ok($foo_role, 'Moose::Meta::Role');
21 isa_ok($foo_role, 'Class::MOP::Module');
23 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
24 is($foo_role->version, '0.01', '... got the right version of FooRole');
28 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
29 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
31 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
34 [ $foo_role->get_method_list() ],
36 '... got the right method list');
41 [ $foo_role->get_attribute_list() ],
43 '... got the right attribute list');
45 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
48 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
49 } '... added the bar attribute okay';
52 [ $foo_role->get_attribute_list() ],
54 '... got the right attribute list');
56 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
59 $foo_role->get_attribute('bar'),
60 { is => 'rw', isa => 'Foo' },
61 '... got the correct description of the bar attribute');
64 $foo_role->add_attribute('baz' => (is => 'ro'));
65 } '... added the baz attribute okay';
68 [ sort $foo_role->get_attribute_list() ],
70 '... got the right attribute list');
72 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
75 $foo_role->get_attribute('baz'),
77 '... got the correct description of the baz attribute');
80 $foo_role->remove_attribute('bar');
81 } '... removed the bar attribute okay';
84 [ $foo_role->get_attribute_list() ],
86 '... got the right attribute list');
88 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
89 ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
93 ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
95 my $method = sub { "FooRole::boo:before" };
97 $foo_role->add_before_method_modifier('boo' => $method);
98 } '... added a method modifier okay';
100 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
101 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
104 [ $foo_role->get_method_modifier_list('before') ],
106 '... got the right list of before method modifiers');