X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Faccessor-default.t;h=fd1108b5a89314a20f974f70cb2cdeecff9937b0;hb=fa93bfb29cca2d07be28c8459e1626a59a80245c;hp=2cec9c04e0b4ac7a5a4793955dd406a0df5392cc;hpb=b1eebd55fe3d34b6afa73a4880737dc91379b71e;p=gitmo%2FMoo.git diff --git a/t/accessor-default.t b/t/accessor-default.t index 2cec9c0..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; @@ -13,6 +14,14 @@ use Test::More; has three => (is => 'ro', default => quote_sub q{ {} }); has four => (is => 'ro', builder => '_build_four'); sub _build_four { {} } + 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 { {} } } sub check { @@ -31,4 +40,18 @@ check three => map Foo->new->{three}, 1..2; check four => map Foo->new->{four}, 1..2; +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'); + done_testing;