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