Commit | Line | Data |
e185c027 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
94b8bbb8 |
6 | use Test::More tests => 29; |
e185c027 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
94b8bbb8 |
10 | use_ok('Moose'); |
e185c027 |
11 | use_ok('Moose::Meta::Role'); |
12 | } |
13 | |
14 | { |
15 | package FooRole; |
16 | |
17 | our $VERSION = '0.01'; |
18 | |
19 | sub foo { 'FooRole::foo' } |
20 | } |
21 | |
68efb014 |
22 | my $foo_role = Moose::Meta::Role->initialize('FooRole'); |
e185c027 |
23 | isa_ok($foo_role, 'Moose::Meta::Role'); |
68efb014 |
24 | isa_ok($foo_role, 'Class::MOP::Module'); |
e185c027 |
25 | |
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'); |
28 | |
29 | # methods ... |
30 | |
31 | ok($foo_role->has_method('foo'), '... FooRole has the foo method'); |
093b12c2 |
32 | is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method'); |
e185c027 |
33 | |
a7d0cd00 |
34 | isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method'); |
35 | |
e185c027 |
36 | is_deeply( |
37 | [ $foo_role->get_method_list() ], |
38 | [ 'foo' ], |
39 | '... got the right method list'); |
40 | |
41 | # attributes ... |
42 | |
43 | is_deeply( |
44 | [ $foo_role->get_attribute_list() ], |
45 | [], |
46 | '... got the right attribute list'); |
47 | |
48 | ok(!$foo_role->has_attribute('bar'), '... FooRole does not have the bar attribute'); |
49 | |
50 | lives_ok { |
51 | $foo_role->add_attribute('bar' => (is => 'rw', isa => 'Foo')); |
52 | } '... added the bar attribute okay'; |
53 | |
54 | is_deeply( |
55 | [ $foo_role->get_attribute_list() ], |
56 | [ 'bar' ], |
57 | '... got the right attribute list'); |
58 | |
59 | ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); |
60 | |
61 | is_deeply( |
62 | $foo_role->get_attribute('bar'), |
63 | { is => 'rw', isa => 'Foo' }, |
64 | '... got the correct description of the bar attribute'); |
65 | |
66 | lives_ok { |
67 | $foo_role->add_attribute('baz' => (is => 'ro')); |
68 | } '... added the baz attribute okay'; |
69 | |
70 | is_deeply( |
71 | [ sort $foo_role->get_attribute_list() ], |
72 | [ 'bar', 'baz' ], |
73 | '... got the right attribute list'); |
74 | |
75 | ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); |
76 | |
77 | is_deeply( |
78 | $foo_role->get_attribute('baz'), |
79 | { is => 'ro' }, |
80 | '... got the correct description of the baz attribute'); |
81 | |
82 | lives_ok { |
83 | $foo_role->remove_attribute('bar'); |
84 | } '... removed the bar attribute okay'; |
85 | |
86 | is_deeply( |
87 | [ $foo_role->get_attribute_list() ], |
88 | [ 'baz' ], |
89 | '... got the right attribute list'); |
90 | |
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'); |
93 | |
0558683c |
94 | # method modifiers |
95 | |
96 | ok(!$foo_role->has_before_method_modifiers('boo'), '... no boo:before modifier'); |
97 | |
98 | my $method = sub { "FooRole::boo:before" }; |
99 | lives_ok { |
100 | $foo_role->add_before_method_modifier('boo' => $method); |
101 | } '... added a method modifier okay'; |
102 | |
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'); |
105 | |
106 | is_deeply( |
107 | [ $foo_role->get_method_modifier_list('before') ], |
108 | [ 'boo' ], |
109 | '... got the right list of before method modifiers'); |