zap all role modifyers, and make the tests pass
[gitmo/Moose.git] / t / 041_role.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 1;
7 use Test::Exception;
8
9 BEGIN {  
10     use_ok('Moose::Role');               
11 }
12
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
23 =begin nonsense
24
25 {
26     package FooRole;
27     use Moose::Role;
28     
29     our $VERSION = '0.01';
30     
31     has 'bar' => (is => 'rw', isa => 'Foo');
32     has 'baz' => (is => 'ro');    
33     
34     sub foo { 'FooRole::foo' }
35     sub boo { 'FooRole::boo' }    
36     
37     before 'boo' => sub { "FooRole::boo:before" };
38     
39     after  'boo' => sub { "FooRole::boo:after1"  }; 
40     after  'boo' => sub { "FooRole::boo:after2"  };        
41     
42     around 'boo' => sub { "FooRole::boo:around" };  
43     
44     override 'bling' => sub { "FooRole::bling:override" };   
45     override 'fling' => sub { "FooRole::fling:override" };  
46     
47     ::dies_ok { extends() } '... extends() is not supported';
48     ::dies_ok { augment() } '... augment() is not supported';    
49     ::dies_ok { inner()   } '... inner() is not supported';        
50 }
51
52 my $foo_role = FooRole->meta;
53 isa_ok($foo_role, 'Moose::Meta::Role');
54
55 isa_ok($foo_role->_role_meta, 'Class::MOP::Class');
56
57 is($foo_role->name, 'FooRole', '... got the right name of FooRole');
58 is($foo_role->version, '0.01', '... got the right version of FooRole');
59
60 # methods ...
61
62 ok($foo_role->has_method('foo'), '... FooRole has the foo method');
63 is($foo_role->get_method('foo'), \&FooRole::foo, '... FooRole got the foo method');
64
65 isa_ok($foo_role->get_method('foo'), 'Moose::Meta::Role::Method');
66
67 ok($foo_role->has_method('boo'), '... FooRole has the boo method');
68 is($foo_role->get_method('boo'), \&FooRole::boo, '... FooRole got the boo method');
69
70 isa_ok($foo_role->get_method('boo'), 'Moose::Meta::Role::Method');
71
72 is_deeply(
73     [ sort $foo_role->get_method_list() ],
74     [ 'boo', 'foo' ],
75     '... got the right method list');
76     
77 # attributes ...
78
79 is_deeply(
80     [ sort $foo_role->get_attribute_list() ],
81     [ 'bar', 'baz' ],
82     '... got the right attribute list');
83
84 ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
85
86 is_deeply(
87     $foo_role->get_attribute('bar'),
88     { is => 'rw', isa => 'Foo' },
89     '... got the correct description of the bar attribute');
90
91 ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
92
93 is_deeply(
94     $foo_role->get_attribute('baz'),
95     { is => 'ro' },
96     '... got the correct description of the baz attribute');
97
98 # method modifiers
99
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]->(), 
102     "FooRole::boo:before", 
103     '... got the right method back');
104
105 is_deeply(
106     [ $foo_role->get_method_modifier_list('before') ],
107     [ 'boo' ],
108     '... got the right list of before method modifiers');
109
110 ok($foo_role->has_after_method_modifiers('boo'), '... now we have a boo:after modifier');
111 is(($foo_role->get_after_method_modifiers('boo'))[0]->(), 
112     "FooRole::boo:after1", 
113     '... got the right method back');
114 is(($foo_role->get_after_method_modifiers('boo'))[1]->(), 
115     "FooRole::boo:after2", 
116     '... got the right method back');    
117
118 is_deeply(
119     [ $foo_role->get_method_modifier_list('after') ],
120     [ 'boo' ],
121     '... got the right list of after method modifiers');
122     
123 ok($foo_role->has_around_method_modifiers('boo'), '... now we have a boo:around modifier');
124 is(($foo_role->get_around_method_modifiers('boo'))[0]->(), 
125     "FooRole::boo:around", 
126     '... got the right method back');
127
128 is_deeply(
129     [ $foo_role->get_method_modifier_list('around') ],
130     [ 'boo' ],
131     '... got the right list of around method modifiers');
132
133 ## overrides
134
135 ok($foo_role->has_override_method_modifier('bling'), '... now we have a bling:override modifier');
136 is($foo_role->get_override_method_modifier('bling')->(), 
137     "FooRole::bling:override", 
138     '... got the right method back');
139
140 ok($foo_role->has_override_method_modifier('fling'), '... now we have a fling:override modifier');
141 is($foo_role->get_override_method_modifier('fling')->(), 
142     "FooRole::fling:override", 
143     '... got the right method back');
144
145 is_deeply(
146     [ sort $foo_role->get_method_modifier_list('override') ],
147     [ 'bling', 'fling' ],
148     '... got the right list of override method modifiers');
149
150 =cut