do not generate an accessor on an rw attr if reader and writer are defined, this...
[gitmo/Moo.git] / t / accessor-default.t
index 1f3fbac..fd1108b 100644 (file)
@@ -1,6 +1,7 @@
 use strictures 1;
 use Test::More;
 
+my $c_ran;
 {
   package Foo;
 
@@ -14,6 +15,13 @@ use Test::More;
   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 {
@@ -34,4 +42,16 @@ 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;