8 sub check_meta_sanity {
9 my ($meta, $class) = @_;
10 local $Test::Builder::Level = $Test::Builder::Level + 1;
11 isa_ok($meta, 'Moose::Meta::Class');
12 is($meta->name, $class);
13 ok($meta->has_method('foo'));
14 isa_ok($meta->get_method('foo'), 'Moose::Meta::Method');
15 ok($meta->has_attribute('bar'));
16 isa_ok($meta->get_attribute('bar'), 'Moose::Meta::Attribute');
23 has bar => (is => 'ro');
26 check_meta_sanity(Foo->meta, 'Foo');
28 Moose::Meta::Class->reinitialize('Foo');
29 check_meta_sanity(Foo->meta, 'Foo');
32 package Foo::Role::Method;
35 has foo => (is => 'rw');
39 package Foo::Role::Attribute;
41 has oof => (is => 'rw');
44 Moose::Util::MetaRole::apply_metaroles(
47 method => ['Foo::Role::Method'],
48 attribute => ['Foo::Role::Attribute'],
51 check_meta_sanity(Foo->meta, 'Foo');
52 does_ok(Foo->meta->get_method('foo'), 'Foo::Role::Method');
53 does_ok(Foo->meta->get_attribute('bar'), 'Foo::Role::Attribute');
55 Moose::Meta::Class->reinitialize('Foo');
56 check_meta_sanity(Foo->meta, 'Foo');
57 does_ok(Foo->meta->get_method('foo'), 'Foo::Role::Method');
58 does_ok(Foo->meta->get_attribute('bar'), 'Foo::Role::Attribute');
60 Foo->meta->get_method('foo')->foo('TEST');
61 Foo->meta->get_attribute('bar')->oof('TSET');
62 is(Foo->meta->get_method('foo')->foo, 'TEST');
63 is(Foo->meta->get_attribute('bar')->oof, 'TSET');
64 Moose::Meta::Class->reinitialize('Foo');
65 check_meta_sanity(Foo->meta, 'Foo');
66 is(Foo->meta->get_method('foo')->foo, 'TEST');
67 is(Foo->meta->get_attribute('bar')->oof, 'TSET');
70 package Bar::Role::Method;
75 package Bar::Role::Attribute;
82 Moose::Util::MetaRole::apply_metaroles(
85 method => ['Bar::Role::Method'],
86 attribute => ['Bar::Role::Attribute'],
90 has bar => (is => 'ro');
93 check_meta_sanity(Bar->meta, 'Bar');
94 does_ok(Bar->meta->get_method('foo'), 'Bar::Role::Method');
95 does_ok(Bar->meta->get_attribute('bar'), 'Bar::Role::Attribute');
97 Moose::Meta::Class->reinitialize('Bar');
98 check_meta_sanity(Bar->meta, 'Bar');
99 does_ok(Bar->meta->get_method('foo'), 'Bar::Role::Method');
100 does_ok(Bar->meta->get_attribute('bar'), 'Bar::Role::Attribute');
101 ok(!Moose::Util::does_role(Bar->meta->get_method('foo'), 'Foo::Role::Method'));
102 ok(!Moose::Util::does_role(Bar->meta->get_attribute('bar'), 'Foo::Role::Attribute'));
104 Moose::Util::MetaRole::apply_metaroles(
107 method => ['Foo::Role::Method'],
108 attribute => ['Foo::Role::Attribute'],
111 check_meta_sanity(Bar->meta, 'Bar');
112 does_ok(Bar->meta->get_method('foo'), 'Bar::Role::Method');
113 does_ok(Bar->meta->get_attribute('bar'), 'Bar::Role::Attribute');
114 does_ok(Bar->meta->get_method('foo'), 'Foo::Role::Method');
115 does_ok(Bar->meta->get_attribute('bar'), 'Foo::Role::Attribute');
118 package Bar::Meta::Method;
120 BEGIN { extends 'Moose::Meta::Method' };
124 package Bar::Meta::Attribute;
126 BEGIN { extends 'Moose::Meta::Attribute' };
129 Moose::Meta::Class->reinitialize(
131 method_metaclass => 'Bar::Meta::Method',
132 attribute_metaclass => 'Bar::Meta::Attribute',
134 check_meta_sanity(Bar->meta, 'Bar');
135 isa_ok(Bar->meta->get_method('foo'), 'Bar::Meta::Method');
136 does_ok(Bar->meta->get_method('foo'), 'Bar::Role::Method');
137 does_ok(Bar->meta->get_method('foo'), 'Foo::Role::Method');
138 isa_ok(Bar->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
139 does_ok(Bar->meta->get_attribute('bar'), 'Bar::Role::Attribute');
140 does_ok(Bar->meta->get_attribute('bar'), 'Foo::Role::Attribute');
143 package Baz::Meta::Class;
145 BEGIN { extends 'Moose::Meta::Class' };
149 return $self->SUPER::initialize(
151 method_metaclass => 'Bar::Meta::Method',
152 attribute_metaclass => 'Bar::Meta::Attribute'
159 use Moose -metaclass => 'Baz::Meta::Class';
161 has bar => (is => 'ro');
164 check_meta_sanity(Baz->meta, 'Baz');
165 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
166 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
167 Moose::Meta::Class->reinitialize('Baz');
168 check_meta_sanity(Baz->meta, 'Baz');
169 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
170 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
172 Moose::Util::MetaRole::apply_metaroles(
175 method => ['Foo::Role::Method'],
176 attribute => ['Foo::Role::Attribute'],
179 check_meta_sanity(Baz->meta, 'Baz');
180 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
181 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
182 does_ok(Baz->meta->get_method('foo'), 'Foo::Role::Method');
183 does_ok(Baz->meta->get_attribute('bar'), 'Foo::Role::Attribute');
186 Moose::Meta::Class->reinitialize(
188 method_metaclass => 'Foo::Meta::Method',
189 attribute_metaclass => 'Foo::Meta::Attribute',