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