10 use Moose::Util::TypeConstraints ();
15 our $VERSION = '0.01';
17 sub foo { 'FooRole::foo' }
20 my $foo_role = Moose::Meta::Role->initialize('FooRole');
21 isa_ok($foo_role, 'Moose::Meta::Role');
22 isa_ok($foo_role, 'Class::MOP::Module');
24 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
25 is($foo_role->version, '0.01', '... got the right version of FooRole');
29 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
30 is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method');
32 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
35 [ $foo_role->get_method_list() ],
37 '... got the right method list');
42 [ $foo_role->get_attribute_list() ],
44 '... got the right attribute list');
46 ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute');
49 $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo'));
50 }, undef, '... added the bar attribute okay' );
53 [ $foo_role->get_attribute_list() ],
55 '... got the right attribute list');
57 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
59 my $bar = $foo_role->get_attribute('bar');
60 is_deeply( $bar->original_options, { is => 'rw', isa => 'Foo' },
61 'original options for bar attribute' );
62 my $bar_for_class = $bar->attribute_for_class('Moose::Meta::Attribute');
64 $bar_for_class->type_constraint,
65 Moose::Util::TypeConstraints::class_type('Foo'),
66 'bar has a Foo class type'
70 $foo_role->add_attribute('baz' => (is => 'ro'));
71 }, undef, '... added the baz attribute okay' );
74 [ sort $foo_role->get_attribute_list() ],
76 '... got the right attribute list');
78 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
80 my $baz = $foo_role->get_attribute('baz');
81 is_deeply( $baz->original_options, { is => 'ro' },
82 'original options for baz attribute' );
85 $foo_role->remove_attribute('bar');
86 }, undef, '... 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 }, undef, '... 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');