Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / roles / role_attrs.t
CommitLineData
f785aad8 1use strict;
2use warnings;
3
4use Test::More;
f785aad8 5
6use Moose ();
7use Moose::Meta::Role;
8use Moose::Util;
9
10my $role1 = Moose::Meta::Role->initialize('Foo');
11$role1->add_attribute( foo => ( is => 'ro' ) );
12
13ok( $role1->has_attribute('foo'), 'Foo role has a foo attribute' );
14
15my $foo_attr = $role1->get_attribute('foo');
16is(
17 $foo_attr->associated_role->name, 'Foo',
18 'associated_role for foo attr is Foo role'
19);
20
21isa_ok(
22 $foo_attr->attribute_for_class('Moose::Meta::Attribute'),
23 'Moose::Meta::Attribute',
24 'attribute returned by ->attribute_for_class'
25);
26
27my $role2 = Moose::Meta::Role->initialize('Bar');
28$role1->apply($role2);
29
30ok( $role2->has_attribute('foo'), 'Bar role has a foo attribute' );
31
32is(
33 $foo_attr->associated_role->name, 'Foo',
34 'associated_role for foo attr is still Foo role'
35);
36
37isa_ok(
38 $foo_attr->attribute_for_class('Moose::Meta::Attribute'),
39 'Moose::Meta::Attribute',
40 'attribute returned by ->attribute_for_class'
41);
42
43my $role3 = Moose::Meta::Role->initialize('Baz');
44my $combined = Moose::Meta::Role->combine( [ $role1->name ], [ $role3->name ] );
45
46ok( $combined->has_attribute('foo'), 'combined role has a foo attribute' );
47
48is(
49 $foo_attr->associated_role->name, 'Foo',
50 'associated_role for foo attr is still Foo role'
51);
52
53done_testing;