7 package Foo::Meta::Attribute;
12 package Foo::Meta::Attribute2;
20 has foo => (is => 'ro');
26 Moose::Util::MetaRole::apply_metaroles(
28 class_metaroles => { attribute => ['Foo::Meta::Attribute'] },
29 role_metaroles => { applied_attribute => ['Foo::Meta::Attribute2'] },
33 has bar => (is => 'ro');
36 ok(Moose::Util::does_role(Foo->meta->get_attribute('bar'), 'Foo::Meta::Attribute'), "attrs defined in the class get the class metarole applied");
37 ok(!Moose::Util::does_role(Foo->meta->get_attribute('bar'), 'Foo::Meta::Attribute2'), "attrs defined in the class don't get the role metarole applied");
38 ok(!Moose::Util::does_role(Foo->meta->get_attribute('foo'), 'Foo::Meta::Attribute'), "attrs defined in the role don't get the metarole applied");
39 ok(!Moose::Util::does_role(Foo->meta->get_attribute('foo'), 'Foo::Meta::Attribute'), "attrs defined in the role don't get the role metarole defined in the class applied");
42 package Bar::Meta::Attribute;
47 package Bar::Meta::Attribute2;
54 Moose::Util::MetaRole::apply_metaroles(
56 class_metaroles => { attribute => ['Bar::Meta::Attribute'] },
57 role_metaroles => { applied_attribute => ['Bar::Meta::Attribute2'] },
60 has foo => (is => 'ro');
68 has bar => (is => 'ro');
71 ok(!Moose::Util::does_role(Bar->meta->get_attribute('bar'), 'Bar::Meta::Attribute'), "attrs defined in the class don't get the class metarole from the role applied");
72 ok(!Moose::Util::does_role(Bar->meta->get_attribute('bar'), 'Bar::Meta::Attribute2'), "attrs defined in the class don't get the role metarole applied");
73 ok(Moose::Util::does_role(Bar->meta->get_attribute('foo'), 'Bar::Meta::Attribute2'), "attrs defined in the role get the role metarole applied");
74 ok(!Moose::Util::does_role(Bar->meta->get_attribute('foo'), 'Bar::Meta::Attribute'), "attrs defined in the role don't get the class metarole applied");
77 package Baz::Meta::Attribute;
82 package Baz::Meta::Attribute2;
89 Moose::Util::MetaRole::apply_metaroles(
91 class_metaroles => { attribute => ['Baz::Meta::Attribute'] },
92 role_metaroles => { applied_attribute => ['Baz::Meta::Attribute2'] },
95 has foo => (is => 'ro');
101 Moose::Util::MetaRole::apply_metaroles(
103 class_metaroles => { attribute => ['Baz::Meta::Attribute'] },
104 role_metaroles => { applied_attribute => ['Baz::Meta::Attribute2'] },
108 has bar => (is => 'ro');
111 ok(Moose::Util::does_role(Baz->meta->get_attribute('bar'), 'Baz::Meta::Attribute'), "attrs defined in the class get the class metarole applied");
112 ok(!Moose::Util::does_role(Baz->meta->get_attribute('bar'), 'Baz::Meta::Attribute2'), "attrs defined in the class don't get the role metarole applied");
113 ok(Moose::Util::does_role(Baz->meta->get_attribute('foo'), 'Baz::Meta::Attribute2'), "attrs defined in the role get the role metarole applied");
114 ok(!Moose::Util::does_role(Baz->meta->get_attribute('foo'), 'Baz::Meta::Attribute'), "attrs defined in the role don't get the class metarole applied");
117 package Accessor::Modifying::Role;
120 around _process_options => sub {
123 my ($name, $params) = @_;
125 $params->{reader} .= '_foo';
140 package Class::With::Trait;
142 Moose::Util::MetaRole::apply_metaroles(
145 attribute => ['Accessor::Modifying::Role'],
157 can_ok('Class::With::Trait', 'foo');
158 can_ok('Class::With::Trait', 'bar_foo');
162 package Role::With::Trait;
164 Moose::Util::MetaRole::apply_metaroles(
167 applied_attribute => ['Accessor::Modifying::Role'],
179 return $self->can('foo_foo');
184 package Class::With::Role::With::Trait;
186 with 'Role::With::Trait';
195 return $self->can('bar');
200 can_ok('Class::With::Role::With::Trait', 'foo_foo');
201 can_ok('Class::With::Role::With::Trait', 'bar');