Skip to content

Commit

Permalink
c3/BUILD fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
haarg committed Apr 15, 2014
1 parent 8466c09 commit 1e0f441
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
27 changes: 23 additions & 4 deletions lib/Method/Generate/BuildAll.pm
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,29 @@ sub _handle_subbuild {

sub buildall_body_for {
my ($self, $into, $me, $args) = @_;
my @builds =
grep *{_getglob($_)}{CODE},
map "${_}::BUILD",
reverse @{Moo::_Utils::_get_linear_isa($into)};
my @builds;
require Moo;
for my $class (@{Moo::_Utils::_get_linear_isa($into)}) {
if ($class eq 'Moo::Object') {
last;
}
my $new = *{_getglob("${class}::new")}{CODE};
if (!defined $new) {
}
elsif (my $defer_target = (Sub::Defer::defer_info($new)||[])->[0]) {
my ($pkg) = ($defer_target =~ /^(.*)::[^:]+$/);
if (!$Moo::MAKERS{$pkg}) {
last;
}
}
else {
last;
}
my $build = "${class}::BUILD";
if (*{_getglob($build)}{CODE}) {
unshift @builds, $build;
}
}
join '', map qq{ ${me}->${_}(${args});\n}, @builds;
}

Expand Down
7 changes: 5 additions & 2 deletions lib/Moo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,18 @@ sub _constructor_maker_for {
$con ? (construction_string => $con->construction_string) : ()
) : (
construction_builder => sub {
'$class->'.$target.'::SUPER::new('
'$class->next::method('
.($target->can('FOREIGNBUILDARGS') ?
'$class->FOREIGNBUILDARGS(@_)' : '@_')
.')'
},
),
subconstructor_handler => (
' if ($Moo::MAKERS{$class}) {'."\n"
.' '.$class.'->_constructor_maker_for($class,'.quotify($target).');'."\n"
.' if ($Moo::MAKERS{$class}{constructor}) {'."\n"
.' return $class->'.$target.'::SUPER::new(@_);'."\n"
.' }'."\n"
.' '.$class.'->_constructor_maker_for($class);'."\n"
.' return $class->new(@_)'.";\n"
.' } elsif ($INC{"Moose.pm"} and my $meta = Class::MOP::get_metaclass_by_name($class)) {'."\n"
.' return $meta->new_object($class->BUILDARGS(@_));'."\n"
Expand Down

0 comments on commit 1e0f441

Please sign in to comment.