From: Matt S Trout Date: Tue, 26 Jun 2012 19:25:23 +0000 (+0000) Subject: remove multi-populate code to fix exists/defined new() bug X-Git-Tag: v0.091010~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0689a5ab016832be48d8e1b724f42a31ac8a0947;p=gitmo%2FMoo.git remove multi-populate code to fix exists/defined new() bug --- diff --git a/Changes b/Changes index 7d4e08c..e9a1532 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - remove multi-populate code to fix exists/defined new() bug - document move to #moose and include repository metadata - no Moo and no Moo::Role - squelch used only once warnings for $Moo::HandleMoose::MOUSE diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 7056200..fe268ba 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -398,11 +398,6 @@ sub _generate_populate_set { } } -sub generate_multi_set { - my ($self, $me, $to_set, $from) = @_; - "\@{${me}}{qw(${\join ' ', @$to_set})} = $from"; -} - sub _generate_core_set { my ($self, $me, $name, $spec, $value) = @_; my $name_str = perlstring $name; diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index e0746d7..080442b 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -136,28 +136,15 @@ _EOA sub _assign_new { my ($self, $spec) = @_; - my (@init, @slots, %test); my $ag = $self->accessor_generator; + my %test; NAME: foreach my $name (sort keys %$spec) { my $attr_spec = $spec->{$name}; - unless ($ag->is_simple_attribute($name, $attr_spec)) { - next NAME unless defined($attr_spec->{init_arg}) - or $ag->has_eager_default($name, $attr_spec); - $test{$name} = $attr_spec->{init_arg}; - next NAME; - } - next NAME unless defined(my $i = $attr_spec->{init_arg}); - push @init, $i; - push @slots, $name; + next NAME unless defined($attr_spec->{init_arg}) + or $ag->has_eager_default($name, $attr_spec); + $test{$name} = $attr_spec->{init_arg}; } - return '' unless @init or %test; - join '', ( - @init - ? ' '.$self->_cap_call($ag->generate_multi_set( - '$new', [ @slots ], '@{$args}{qw('.join(' ',@init).')}', $spec - )).";\n" - : '' - ), map { + join '', map { my $arg_key = perlstring($test{$_}); my $test = "exists \$args->{$arg_key}"; my $source = "\$args->{$arg_key}"; diff --git a/t/undef-bug.t b/t/undef-bug.t new file mode 100644 index 0000000..c3ed934 --- /dev/null +++ b/t/undef-bug.t @@ -0,0 +1,13 @@ +use Test::More tests => 1; + +package Foo; +use Moo; + +has this => (is => 'ro'); + +package main; + +my $foo = Foo->new; + +ok not(exists($foo->{this})), + "new objects don't have undef attributes";