Commit | Line | Data |
e185c027 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
fa476537 |
6 | use Test::More tests => 37; |
e185c027 |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
10 | use_ok('Moose::Role'); |
11 | } |
12 | |
38f1204c |
13 | =pod |
14 | |
15 | NOTE: |
16 | |
17 | Should we be testing here that the has & override |
18 | are injecting their methods correctly? In other |
19 | words, should 'has_method' return true for them? |
20 | |
21 | =cut |
22 | |
e185c027 |
23 | { |
24 | package FooRole; |
e185c027 |
25 | use Moose::Role; |
26 | |
27 | our $VERSION = '0.01'; |
28 | |
29 | has 'bar' => (is => 'rw', isa => 'Foo'); |
30 | has 'baz' => (is => 'ro'); |
31 | |
32 | sub foo { 'FooRole::foo' } |
bdabd620 |
33 | sub boo { 'FooRole::boo' } |
0558683c |
34 | |
35 | before 'boo' => sub { "FooRole::boo:before" }; |
36 | |
37 | after 'boo' => sub { "FooRole::boo:after1" }; |
38 | after 'boo' => sub { "FooRole::boo:after2" }; |
39 | |
40 | around 'boo' => sub { "FooRole::boo:around" }; |
41 | |
42 | override 'bling' => sub { "FooRole::bling:override" }; |
43 | override 'fling' => sub { "FooRole::fling:override" }; |
44 | |
bdabd620 |
45 | ::dies_ok { extends() } '... extends() is not supported'; |
0558683c |
46 | ::dies_ok { augment() } '... augment() is not supported'; |
47 | ::dies_ok { inner() } '... inner() is not supported'; |
fd75e12b |
48 | |
49 | no Moose::Role; |
e185c027 |
50 | } |
51 | |
52 | my $foo_role = FooRole->meta; |
53 | isa_ok($foo_role, 'Moose::Meta::Role'); |
68efb014 |
54 | isa_ok($foo_role, 'Class::MOP::Module'); |
e185c027 |
55 | |
56 | is($foo_role->name, 'FooRole', '... got the right name of FooRole'); |
57 | is($foo_role->version, '0.01', '... got the right version of FooRole'); |
58 | |
59 | # methods ... |
60 | |
61 | ok($foo_role->has_method('foo'), '... FooRole has the foo method'); |
093b12c2 |
62 | is($foo_role->get_method('foo')->body, \&FooRole::foo, '... FooRole got the foo method'); |
e185c027 |
63 | |
a7d0cd00 |
64 | isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method'); |
65 | |
bdabd620 |
66 | ok($foo_role->has_method('boo'), '... FooRole has the boo method'); |
093b12c2 |
67 | is($foo_role->get_method('boo')->body, \&FooRole::boo, '... FooRole got the boo method'); |
bdabd620 |
68 | |
69 | isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method'); |
70 | |
e185c027 |
71 | is_deeply( |
bdabd620 |
72 | [ sort $foo_role->get_method_list() ], |
73 | [ 'boo', 'foo' ], |
e185c027 |
74 | '... got the right method list'); |
fa476537 |
75 | |
76 | ok(FooRole->can('foo'), "locally defined methods are still there"); |
77 | ok(!FooRole->can('has'), "sugar was unimported"); |
78 | |
e185c027 |
79 | # attributes ... |
80 | |
81 | is_deeply( |
82 | [ sort $foo_role->get_attribute_list() ], |
83 | [ 'bar', 'baz' ], |
84 | '... got the right attribute list'); |
85 | |
86 | ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); |
87 | |
88 | is_deeply( |
89 | $foo_role->get_attribute('bar'), |
90 | { is => 'rw', isa => 'Foo' }, |
91 | '... got the correct description of the bar attribute'); |
92 | |
93 | ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); |
94 | |
95 | is_deeply( |
96 | $foo_role->get_attribute('baz'), |
97 | { is => 'ro' }, |
98 | '... got the correct description of the baz attribute'); |
99 | |
0558683c |
100 | # method modifiers |
101 | |
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]->(), |
104 | "FooRole::boo:before", |
105 | '... got the right method back'); |
106 | |
107 | is_deeply( |
108 | [ $foo_role->get_method_modifier_list('before') ], |
109 | [ 'boo' ], |
110 | '... got the right list of before method modifiers'); |
111 | |
112 | ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier'); |
113 | is(($foo_role->get_after_method_modifiers('boo'))[0]->(), |
114 | "FooRole::boo:after1", |
115 | '... got the right method back'); |
116 | is(($foo_role->get_after_method_modifiers('boo'))[1]->(), |
117 | "FooRole::boo:after2", |
118 | '... got the right method back'); |
119 | |
120 | is_deeply( |
121 | [ $foo_role->get_method_modifier_list('after') ], |
122 | [ 'boo' ], |
123 | '... got the right list of after method modifiers'); |
124 | |
125 | ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier'); |
126 | is(($foo_role->get_around_method_modifiers('boo'))[0]->(), |
127 | "FooRole::boo:around", |
128 | '... got the right method back'); |
129 | |
130 | is_deeply( |
131 | [ $foo_role->get_method_modifier_list('around') ], |
132 | [ 'boo' ], |
133 | '... got the right list of around method modifiers'); |
134 | |
135 | ## overrides |
136 | |
137 | ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier'); |
138 | is($foo_role->get_override_method_modifier('bling')->(), |
139 | "FooRole::bling:override", |
140 | '... got the right method back'); |
141 | |
142 | ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier'); |
143 | is($foo_role->get_override_method_modifier('fling')->(), |
144 | "FooRole::fling:override", |
145 | '... got the right method back'); |
146 | |
147 | is_deeply( |
148 | [ sort $foo_role->get_method_modifier_list('override') ], |
149 | [ 'bling', 'fling' ], |
150 | '... got the right list of override method modifiers'); |
151 | |