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