6 use Test::More tests => 26;
10 use Mouse::Meta::Role;
17 our $VERSION = '0.01';
19 sub foo { 'FooRole::foo' }
22 my $foo_role = Mouse::Meta::Role->initialize('FooRole');
23 isa_ok($foo_role, 'Mouse::Meta::Role');
24 #isa_ok($foo_role, 'Class::MOP::Module');
26 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
27 is($foo_role->version, '0.01', '... got the right version of FooRole');
31 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
32 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
34 isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::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 local $TODO = 'Mouse does not support role attributes';
64 join('|', %{$foo_role->get_attribute('bar')}),
65 join('|', %{+{ 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')->{is},
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');