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' };
130 Moose::Meta::Class->reinitialize(
132 method_metaclass => 'Bar::Meta::Method',
133 attribute_metaclass => 'Bar::Meta::Attribute',
138 package Baz::Meta::Class;
140 BEGIN { extends 'Moose::Meta::Class' };
144 return $self->SUPER::initialize(
146 method_metaclass => 'Bar::Meta::Method',
147 attribute_metaclass => 'Bar::Meta::Attribute'
154 use Moose -metaclass => 'Baz::Meta::Class';
156 has bar => (is => 'ro');
159 check_meta_sanity(Baz->meta, 'Baz');
160 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
161 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
162 Moose::Meta::Class->reinitialize('Baz');
163 check_meta_sanity(Baz->meta, 'Baz');
164 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
165 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
167 Moose::Util::MetaRole::apply_metaroles(
170 method => ['Foo::Role::Method'],
171 attribute => ['Foo::Role::Attribute'],
174 check_meta_sanity(Baz->meta, 'Baz');
175 isa_ok(Baz->meta->get_method('foo'), 'Bar::Meta::Method');
176 isa_ok(Baz->meta->get_attribute('bar'), 'Bar::Meta::Attribute');
177 does_ok(Baz->meta->get_method('foo'), 'Foo::Role::Method');
178 does_ok(Baz->meta->get_attribute('bar'), 'Foo::Role::Attribute');
181 package Baz::Meta::Method;
183 extends 'Moose::Meta::Method';
187 package Baz::Meta::Attribute;
189 extends 'Moose::Meta::Attribute';
193 Moose::Meta::Class->reinitialize(
195 method_metaclass => 'Baz::Meta::Method',
196 attribute_metaclass => 'Baz::Meta::Attribute',