merged with delegation_bugs branch
[gitmo/MooseX-ClassAttribute.git] / t / 08-role-composition-of-delegates.t
CommitLineData
a9d2b1a7 1
2# Reported in https://rt.cpan.org/Public/Bug/Display.html?id=59572
3
4use strict;
5use warnings;
6
7use Test::More tests => 4;
8#use Test::NoWarnings;
9use Test::Exception;
10
11{
12 package Role1;
13 use Moose::Role;
14
15 # I do nothing!
16}
17{
18 package Role2;
19
20 use Moose::Role;
21 use MooseX::ClassAttribute;
22
23 class_has attr => (
24 is => 'ro', isa => 'HashRef[Str]',
25 lazy => 1,
26 default => sub { {} },
27 traits => ['Hash'],
28 handles => {
29 has_attr => 'exists',
30 },
31 );
32
33 has foo => ( is => 'rw' );
34
35 sub normal_method
36 {
37 Test::More::pass('a regular method from the role is composed');
38 }
39}
40
41{
42 package Foo;
43 use strict; use warnings;
44 use Moose;
45 with 'Role1', 'Role2';
46 1;
47}
48
49package main;
50local $TODO = 'Class attributes are lost during role composition';
51# this runs, so Role2 did get composed...
52Foo->normal_method;
53ok(Foo->can('foo'), 'Standard attribute applied ok');
54
55# Except the delegated method ended up in the wrong place!
56
57# ..and MX::Class never got applied properly!
58ok(Moose::Util::does_role(Foo->meta, 'MooseX::ClassAttribute::Trait::Class'),
59 'metaclass gets MX:CA metaclass trait');
60
61# in Moose 1.08/MooseX::ClassAttribute 0.16, this dies with:
62# Can't locate object method "has_attr" via package "Foo"
63lives_ok { Foo->has_attr('key') }
64 'Delegated method from native attribute trait is properly composed from a role composed in a list of roles';
65