From: Arthur Axel 'fREW' Schmidt Date: Sat, 21 Jul 2012 06:14:31 +0000 (-0500) Subject: ignore required when default or builder is present X-Git-Tag: v1.000001~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c9a5dcbd2dab679f195484b996e0511bfdf47107;p=gitmo%2FMoo.git ignore required when default or builder is present --- diff --git a/Changes b/Changes index 57e5ebd..667e9cb 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - ignore required when default or builder is present - document Moo versus Any::Moose in brief with article link - remove quote_sub from SYNOPSIS and has docs, expand Sub::Quote section - localize @_ when inlining quote_sub'ed isa checks (fixes lazy+isa+default) diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index 080442b..f89dee9 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -159,8 +159,10 @@ sub _check_required { my ($self, $spec) = @_; my @required_init = map $spec->{$_}{init_arg}, - grep $spec->{$_}{required}, - sort keys %$spec; + grep { + my %s = %{$spec->{$_}}; # ignore required if default or builder set + $s{required} and not($s{builder} or $s{default}) + } sort keys %$spec; return '' unless @required_init; ' if (my @missing = grep !exists $args->{$_}, qw(' .join(' ',@required_init).')) {'."\n" diff --git a/t/accessor-default.t b/t/accessor-default.t index 3c02d75..5ff20f8 100644 --- a/t/accessor-default.t +++ b/t/accessor-default.t @@ -16,6 +16,7 @@ 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{ {} }); } sub check { @@ -38,4 +39,6 @@ check five => map Foo->new->{five}, 1..2; check six => map Foo->new->{six}, 1..2; +check seven => map Foo->new->{seven}, 1..2; + done_testing;