From: Graham Knop Date: Tue, 18 Jun 2013 23:29:30 +0000 (-0400) Subject: test constructor after composing multiple roles X-Git-Tag: v1.003000~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=92f126f109364e056824c01b08d0c1627fb123fa;p=gitmo%2FMoo.git test constructor after composing multiple roles --- diff --git a/t/compose-roles.t b/t/compose-roles.t index 29a3342..53ec5bb 100644 --- a/t/compose-roles.t +++ b/t/compose-roles.t @@ -28,4 +28,27 @@ foreach my $combo ( is(ref($object), $combined, 'Object reblessed into correct class'); } +{ + package RoleWithAttr; + use Moo::Role; + + has attr1 => (is => 'rw'); + + package RoleWithAttr2; + use Moo::Role; + + has attr2 => (is => 'rw'); + + package ClassWithAttr; + use Moo; + + has attr3 => (is => 'rw'); +} + +Moo::Role->apply_roles_to_package('ClassWithAttr', 'RoleWithAttr', 'RoleWithAttr2'); +my $o = ClassWithAttr->new(attr1 => 1, attr2 => 2, attr3 => 3); +is($o->attr1, 1, 'attribute from role works'); +is($o->attr2, 2, 'attribute from role 2 works'); +is($o->attr3, 3, 'attribute from base class works'); + done_testing;