6 use Test::More tests => 28;
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');
36 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
39 [ $foo_role->get_method_list() ],
41 '... got the right method list');
46 [ $foo_role->get_attribute_list() ],
48 '... got the right attribute list');
50 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
53 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
54 } '... added the bar attribute okay';
57 [ $foo_role->get_attribute_list() ],
59 '... got the right attribute list');
61 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
64 $foo_role->get_attribute('bar'),
65 { is => 'rw', isa => 'Foo' },
66 '... got the correct description of the bar attribute');
69 $foo_role->add_attribute('baz' => (is => 'ro'));
70 } '... added the baz attribute okay';
73 [ sort $foo_role->get_attribute_list() ],
75 '... got the right attribute list');
77 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
80 $foo_role->get_attribute('baz'),
82 '... got the correct description of the baz attribute');
85 $foo_role->remove_attribute('bar');
86 } '... removed the bar attribute okay';
89 [ $foo_role->get_attribute_list() ],
91 '... got the right attribute list');
93 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
94 ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
98 ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
100 my $method = sub { "FooRole::boo:before" };
102 $foo_role->add_before_method_modifier('boo' => $method);
103 } '... added a method modifier okay';
105 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
106 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
109 [ $foo_role->get_method_modifier_list('before') ],
111 '... got the right list of before method modifiers');