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