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');
58 my $bar = $foo_role->get_attribute('bar');
59 is( $bar->get_read_method, 'bar', 'bar has a reader named bar' );
60 is( $bar->get_write_method, 'bar', 'bar has a writer named bar' );
62 $bar->type_constraint,
63 Moose::Util::TypeConstraints::class_type('Foo'),
64 'bar has a Foo class type'
68 $foo_role->add_attribute('baz' => (is => 'ro'));
69 } '... added the baz attribute okay';
72 [ sort $foo_role->get_attribute_list() ],
74 '... got the right attribute list');
76 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
78 my $baz = $foo_role->get_attribute('baz');
79 is( $baz->get_read_method, 'baz', 'baz has a reader named baz' );
80 is( $baz->get_write_method, undef, 'baz does not have a writer' );
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_before_method_modifiers('boo'), '... no boo:before modifier');
98 my $method = sub { "FooRole::boo:before" };
100 $foo_role->add_before_method_modifier('boo' => $method);
101 } '... added a method modifier okay';
103 ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier');
104 is(($foo_role->get_before_method_modifiers('boo'))[0], $method, '... got the right method back');
107 [ $foo_role->get_method_modifier_list('before') ],
109 '... got the right list of before method modifiers');