X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-default.t;h=fd50924ba98b2d31668eefee119c4eeca2ee470d;hb=040b273865600d815731e915e4806c8618486e25;hp=3c02d7530d0a9e696d2f0bbd44b13928e805bcbf;hpb=e8dc52018eeed58688ed4d0fd233d4ac4837d7b2;p=gitmo%2FMoo.git diff --git a/t/accessor-default.t b/t/accessor-default.t index 3c02d75..fd50924 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; @@ -16,6 +17,15 @@ use Test::More; has five => (is => 'ro', init_arg => undef, default => sub { {} }); 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 { {} } + has ten => (is => 'lazy', default => 5 ); + has eleven => (is => 'ro', default => 5 ); + has twelve => (is => 'lazy', default => 0 ); + has thirteen => (is => 'ro', default => 0 ); } sub check { @@ -38,4 +48,19 @@ check five => map Foo->new->{five}, 1..2; 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'); + +is(Foo->new->ten, 5, 'non-ref default'); +is(Foo->new->eleven, 5, 'eager non-ref default'); +is(Foo->new->twelve, 0, 'false non-ref default'); +is(Foo->new->thirteen, 0, 'eager false non-ref default'); + done_testing;