From: Graham Knop Date: Sun, 5 May 2013 17:50:43 +0000 (-0400) Subject: test for eager defaults in role applied to object X-Git-Tag: v1.003000~23 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f52ab9760e1e6b869d407e7f0158dd4def096446;p=gitmo%2FMoo.git test for eager defaults in role applied to object --- diff --git a/t/accessor-roles.t b/t/accessor-roles.t index d2ab470..5fc5e09 100644 --- a/t/accessor-roles.t +++ b/t/accessor-roles.t @@ -12,6 +12,10 @@ use Sub::Quote; package One::P2; use Moo::Role; has three => (is => 'ro', default => sub { 'three' }); + has four => (is => 'ro', lazy => 1, default => sub { 'four' }, predicate => 1); + + package One::P3; use Moo::Role; + has '+three' => (is => 'ro', default => sub { 'three' }); } my $combined = Moo::Role->create_class_with_roles('One', qw(One::P1 One::P2)); @@ -39,4 +43,13 @@ is $c->three, "three", "attr default set from role"; is(Two->new->two, 'II', "overwriting accessors using +attr works"); +my $o = One->new; +Moo::Role->apply_roles_to_object($o, 'One::P2'); +is($o->three, 'three', 'attr default set from role applied to object'); +ok(!$o->has_four, 'lazy attr default not set on apply'); + +$o = $combined->new(three => '3'); +Moo::Role->apply_roles_to_object($o, 'One::P3'); +is($o->three, '3', 'attr default not used when already set when role applied to object'); + done_testing;