From: Matt S Trout Date: Sat, 21 Jul 2012 15:36:50 +0000 (+0000) Subject: test lazy coerce X-Git-Tag: v1.000001~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e6c7abb4196635b2ceb962df4aaf36e596a26c07;p=gitmo%2FMoo.git test lazy coerce --- diff --git a/t/accessor-default.t b/t/accessor-default.t index 5ff20f8..fd1108b 100644 --- a/t/accessor-default.t +++ b/t/accessor-default.t @@ -1,6 +1,7 @@ use strictures 1; use Test::More; +my $c_ran; { package Foo; @@ -17,6 +18,10 @@ use Test::More; has six => (is => 'ro', builder => 1); sub _build_six { {} } has seven => (is => 'ro', required => 1, default => quote_sub q{ {} }); + has eight => (is => 'ro', builder => '_build_eight', coerce => sub { $c_ran = 1; $_[0] }); + sub _build_eight { {} } + has nine => (is => 'lazy', coerce => sub { $c_ran = 1; $_[0] }); + sub _build_nine { {} } } sub check { @@ -41,4 +46,12 @@ check six => map Foo->new->{six}, 1..2; check seven => map Foo->new->{seven}, 1..2; +check eight => map Foo->new->{eight}, 1..2; +ok($c_ran, 'coerce defaults'); + +$c_ran = 0; + +check nine => map Foo->new->nine, 1..2; +ok($c_ran, 'coerce lazy default'); + done_testing;