Commit | Line | Data |
e185c027 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
bdabd620 |
6 | use Test::More tests => 35; |
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' } |
e185c027 |
34 | |
35 | before 'boo' => sub { "FooRole::boo:before" }; |
bdabd620 |
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 | |
45 | ::dies_ok { extends() } '... extends() is not supported'; |
46 | ::dies_ok { augment() } '... augment() is not supported'; |
47 | ::dies_ok { inner() } '... inner() is not supported'; |
e185c027 |
48 | } |
49 | |
50 | my $foo_role = FooRole->meta; |
51 | isa_ok($foo_role, 'Moose::Meta::Role'); |
52 | |
bdabd620 |
53 | isa_ok($foo_role->_role_meta, 'Class::MOP::Class'); |
e185c027 |
54 | |
55 | is($foo_role->name, 'FooRole', '... got the right name of FooRole'); |
56 | is($foo_role->version, '0.01', '... got the right version of FooRole'); |
57 | |
58 | # methods ... |
59 | |
60 | ok($foo_role->has_method('foo'), '... FooRole has the foo method'); |
61 | is($foo_role->get_method('foo'), \&FooRole::foo, '... FooRole got the foo method'); |
62 | |
a7d0cd00 |
63 | isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method'); |
64 | |
bdabd620 |
65 | ok($foo_role->has_method('boo'), '... FooRole has the boo method'); |
66 | is($foo_role->get_method('boo'), \&FooRole::boo, '... FooRole got the boo method'); |
67 | |
68 | isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method'); |
69 | |
e185c027 |
70 | is_deeply( |
bdabd620 |
71 | [ sort $foo_role->get_method_list() ], |
72 | [ 'boo', 'foo' ], |
e185c027 |
73 | '... got the right method list'); |
74 | |
75 | # attributes ... |
76 | |
77 | is_deeply( |
78 | [ sort $foo_role->get_attribute_list() ], |
79 | [ 'bar', 'baz' ], |
80 | '... got the right attribute list'); |
81 | |
82 | ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute'); |
83 | |
84 | is_deeply( |
85 | $foo_role->get_attribute('bar'), |
86 | { is => 'rw', isa => 'Foo' }, |
87 | '... got the correct description of the bar attribute'); |
88 | |
89 | ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute'); |
90 | |
91 | is_deeply( |
92 | $foo_role->get_attribute('baz'), |
93 | { is => 'ro' }, |
94 | '... got the correct description of the baz attribute'); |
95 | |
96 | # method modifiers |
97 | |
80572233 |
98 | ok($foo_role->has_before_method_modifiers('boo'), '... now we have a boo:before modifier'); |
99 | is(($foo_role->get_before_method_modifiers('boo'))[0]->(), |
e185c027 |
100 | "FooRole::boo:before", |
101 | '... got the right method back'); |
102 | |
103 | is_deeply( |
104 | [ $foo_role->get_method_modifier_list('before') ], |
105 | [ 'boo' ], |
106 | '... got the right list of before method modifiers'); |
107 | |
bdabd620 |
108 | ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier'); |
109 | is(($foo_role->get_after_method_modifiers('boo'))[0]->(), |
110 | "FooRole::boo:after1", |
111 | '... got the right method back'); |
112 | is(($foo_role->get_after_method_modifiers('boo'))[1]->(), |
113 | "FooRole::boo:after2", |
114 | '... got the right method back'); |
115 | |
116 | is_deeply( |
117 | [ $foo_role->get_method_modifier_list('after') ], |
118 | [ 'boo' ], |
119 | '... got the right list of after method modifiers'); |
120 | |
121 | ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier'); |
122 | is(($foo_role->get_around_method_modifiers('boo'))[0]->(), |
123 | "FooRole::boo:around", |
124 | '... got the right method back'); |
125 | |
126 | is_deeply( |
127 | [ $foo_role->get_method_modifier_list('around') ], |
128 | [ 'boo' ], |
129 | '... got the right list of around method modifiers'); |
130 | |
131 | ## overrides |
132 | |
133 | ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier'); |
134 | is($foo_role->get_override_method_modifier('bling')->(), |
135 | "FooRole::bling:override", |
136 | '... got the right method back'); |
137 | |
138 | ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier'); |
139 | is($foo_role->get_override_method_modifier('fling')->(), |
140 | "FooRole::fling:override", |
141 | '... got the right method back'); |
142 | |
143 | is_deeply( |
144 | [ sort $foo_role->get_method_modifier_list('override') ], |
145 | [ 'bling', 'fling' ], |
146 | '... got the right list of override method modifiers'); |
147 | |