6 use Test::More tests => 26;
10 use Test::Mouse; # Mouse::Meta::Module->version
11 use Mouse::Meta::Role;
16 our $VERSION = '0.01';
18 sub foo { 'FooRole::foo' }
21 my $foo_role = Mouse::Meta::Role->initialize('FooRole');
22 isa_ok($foo_role, 'Mouse::Meta::Role');
23 #isa_ok($foo_role, 'Class::MOP::Module');
25 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
26 is($foo_role->version, '0.01', '... got the right version of FooRole');
30 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
31 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
33 isa_ok($foo_role->get_method('foo'), 'Mouse::Meta::Role::Method');
36 [ $foo_role->get_method_list() ],
38 '... got the right method list');
43 [ $foo_role->get_attribute_list() ],
45 '... got the right attribute list');
47 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
50 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
51 } '... added the bar attribute okay';
54 [ $foo_role->get_attribute_list() ],
56 '... got the right attribute list');
58 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
61 join('|', %{$foo_role->get_attribute('bar')}),
62 join('|', %{+{ is => 'rw', isa => 'Foo' }}),
63 '... got the correct description of the bar attribute');
66 $foo_role->add_attribute('baz' => (is => 'ro'));
67 } '... added the baz attribute okay';
70 [ sort $foo_role->get_attribute_list() ],
72 '... got the right attribute list');
74 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
77 $foo_role->get_attribute('baz'),
79 '... got the correct description of the baz attribute');
82 $foo_role->remove_attribute('bar');
83 } '... removed the bar attribute okay';
86 [ $foo_role->get_attribute_list() ],
88 '... got the right attribute list');
90 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
91 ok($foo_role->has_attribute('baz'), '... FooRole does still have the baz attribute');
95 ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier');
97 my $method = sub { "FooRole::boo:before" };
99 $foo_role->add_before_method_modifier('boo' => $method);
100 } '... added a method modifier okay';
102 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
103 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
106 [ $foo_role->get_method_modifier_list('before') ],
108 '... got the right list of before method modifiers');