6 use Test::More tests => 27;
10 use_ok('Moose::Meta::Role');
16 our $VERSION = '0.01';
18 sub foo { 'FooRole::foo' }
21 my $foo_role = Moose::Meta::Role->new(
22 role_name => 'FooRole'
24 isa_ok($foo_role, 'Moose::Meta::Role');
26 isa_ok($foo_role->role_meta, 'Class::MOP::Class');
28 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
29 is($foo_role->version, '0.01', '... got the right version of FooRole');
33 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
34 is($foo_role->get_method('foo'), \&FooRole::foo, '... FooRole got the foo method');
37 [ $foo_role->get_method_list() ],
39 '... got the right method list');
44 [ $foo_role->get_attribute_list() ],
46 '... got the right attribute list');
48 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
51 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
52 } '... added the bar attribute okay';
55 [ $foo_role->get_attribute_list() ],
57 '... got the right attribute list');
59 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
62 $foo_role->get_attribute('bar'),
63 { is => 'rw', isa => 'Foo' },
64 '... got the correct description of the bar attribute');
67 $foo_role->add_attribute('baz' => (is => 'ro'));
68 } '... added the baz attribute okay';
71 [ sort $foo_role->get_attribute_list() ],
73 '... got the right attribute list');
75 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
78 $foo_role->get_attribute('baz'),
80 '... got the correct description of the baz attribute');
83 $foo_role->remove_attribute('bar');
84 } '... removed the bar attribute okay';
87 [ $foo_role->get_attribute_list() ],
89 '... got the right attribute list');
91 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
92 ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
96 ok(!$foo_role->has_method_modifier('before' => 'boo'), '... no boo:before modifier');
98 my $method = sub { "FooRole::boo:before" };
100 $foo_role->add_method_modifier('before' => (
103 } '... added a method modifier okay';
105 ok($foo_role->has_method_modifier('before' => 'boo'), '... now we have a boo:before modifier');
106 is($foo_role->get_method_modifier('before' => 'boo'), $method, '... got the right method back');
109 [ $foo_role->get_method_modifier_list('before') ],
111 '... got the right list of before method modifiers');