correct captures assignment in quote_sub
[gitmo/Moo.git] / xt / moo-roles-into-moose-class.t
CommitLineData
7127b94e 1use strict;
04c82717 2use warnings;
7127b94e 3use Test::More;
ac0a2c9a 4use Test::Fatal;
04c82717 5
7127b94e 6{
7 package Foo;
8 use Moo::Role;
167455a0 9 # if we autoclean here there's nothing left and then load_class tries
10 # to require Foo during Moose application and everything breaks.
7127b94e 11}
12{
13 package Bar;
14 use Moo::Role;
15 use namespace::autoclean;
04c82717 16
17 has attr => (
18 is => 'ro'
19 );
20
21 sub thing {}
7127b94e 22}
23{
04c82717 24 package Baz;
25 use Moose;
26 no Moose;
27
28 ::ok(!__PACKAGE__->can('has'), 'No has function after no Moose;');
29 Moose::with('Baz', 'Bar');
30}
31
32::is(Baz->can('thing'), Bar->can('thing'), 'Role copies method correctly');
33::ok(Baz->can('attr'), 'Attr accessor correct');
167455a0 34::ok(!Bar->can('has'), 'Moo::Role sugar removed by autoclean');
35::ok(!Bar->can('with'), 'Role::Tiny sugar removed by autoclean');
04c82717 36::ok(!Baz->can('has'), 'Sugar not copied');
37
38{
7127b94e 39 package Bax;
40 use Moose;
41 with qw/
42 Foo
43 Bar
44 /;
45}
46
ac0a2c9a 47{
48 package Baw;
49 use Moo::Role;
50 has attr => (
51 is => 'ro',
52 traits => ['Array'],
53 default => sub { [] },
54 handles => {
55 push_attr => 'push',
56 },
57 );
58}
59{
60 package Buh;
61 use Moose;
62 with 'Baw';
63}
64
65is exception {
66 Buh->new->push_attr(1);
67}, undef, 'traits in role attributes are inflated properly';
68
7127b94e 69done_testing;
70