From: Graham Knop Date: Wed, 19 Jun 2013 14:32:09 +0000 (-0400) Subject: remove mechanism for specifying superclass in _constructor_maker_for X-Git-Tag: v1.003000~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8dee08c10f9b63372dff89d38b37b175cdda4489;p=gitmo%2FMoo.git remove mechanism for specifying superclass in _constructor_maker_for This mechanism isn't necessary, and leads to problems when the superclass is a Moo class but its constructor hasn't been generated yet. --- diff --git a/lib/Moo.pm b/lib/Moo.pm index 6899253..bcc4b71 100644 --- a/lib/Moo.pm +++ b/lib/Moo.pm @@ -135,32 +135,27 @@ sub _accessor_maker_for { } sub _constructor_maker_for { - my ($class, $target, $select_super) = @_; + my ($class, $target) = @_; return unless $MAKERS{$target}; $MAKERS{$target}{constructor} ||= do { require Method::Generate::Constructor; require Sub::Defer; my ($moo_constructor, $con); - if ($select_super && $MAKERS{$select_super}) { - $moo_constructor = 1; - $con = $MAKERS{$select_super}{constructor}; - } else { - my $t_new = $target->can('new'); - if ($t_new) { - if ($t_new == Moo::Object->can('new')) { + my $t_new = $target->can('new'); + if ($t_new) { + if ($t_new == Moo::Object->can('new')) { + $moo_constructor = 1; + } elsif (my $defer_target = (Sub::Defer::defer_info($t_new)||[])->[0]) { + my ($pkg) = ($defer_target =~ /^(.*)::[^:]+$/); + if ($MAKERS{$pkg}) { $moo_constructor = 1; - } elsif (my $defer_target = (Sub::Defer::defer_info($t_new)||[])->[0]) { - my ($pkg) = ($defer_target =~ /^(.*)::[^:]+$/); - if ($MAKERS{$pkg}) { - $moo_constructor = 1; - $con = $MAKERS{$pkg}{constructor}; - } + $con = $MAKERS{$pkg}{constructor}; } - } else { - $moo_constructor = 1; # no other constructor, make a Moo one } - }; + } else { + $moo_constructor = 1; # no other constructor, make a Moo one + } ($con ? ref($con) : 'Method::Generate::Constructor') ->new( package => $target, diff --git a/lib/Moo/Role.pm b/lib/Moo/Role.pm index 0abae74..0f93a78 100644 --- a/lib/Moo/Role.pm +++ b/lib/Moo/Role.pm @@ -256,7 +256,7 @@ sub create_class_with_roles { $Moo::MAKERS{$new_name} = {}; $me->_handle_constructor( - $new_name, [ map @{$INFO{$_}{attributes}||[]}, @roles ], $superclass + $new_name, [ map @{$INFO{$_}{attributes}||[]}, @roles ] ); return $new_name; @@ -276,14 +276,14 @@ sub _install_single_modifier { } sub _handle_constructor { - my ($me, $to, $attr_info, $superclass) = @_; + my ($me, $to, $attr_info) = @_; return unless $attr_info && @$attr_info; if ($INFO{$to}) { push @{$INFO{$to}{attributes}||=[]}, @$attr_info; } else { # only fiddle with the constructor if the target is a Moo class if ($INC{"Moo.pm"} - and my $con = Moo->_constructor_maker_for($to, $superclass)) { + and my $con = Moo->_constructor_maker_for($to)) { # shallow copy of the specs since the constructor will assign an index $con->register_attribute_specs(map ref() ? { %$_ } : $_, @$attr_info); }