fix BUILDALL constructor
[gitmo/Moo.git] / lib / Method / Generate / BuildAll.pm
CommitLineData
098a367b 1package Method::Generate::BuildAll;
2
3use strictures 1;
b1eebd55 4use base qw(Moo::Object);
098a367b 5use Sub::Quote;
b1eebd55 6use Moo::_mro;
7use Moo::_Utils;
9aa500f6 8use B 'perlstring';
098a367b 9
10sub generate_method {
11 my ($self, $into) = @_;
077bd026 12 quote_sub "${into}::BUILDALL", join '',
13 qq{ my \$self = shift;\n},
9aa500f6 14 qq{ my \$class = ref \$self;\n},
15 ' if ('. perlstring($into) ." ne \$class) {\n",
16 qq{ return \$self->\${\\(\$Moo::Object::BUILD_MAKER->generate_method(\$class))}(\@_);\n},
17 " } else {\n",
18 $self->buildall_body_for($into, '$self', '@_'),
19 " }\n",
077bd026 20 qq{ return \$self\n};
21}
22
23sub buildall_body_for {
24 my ($self, $into, $me, $args) = @_;
098a367b 25 my @builds =
26 grep *{_getglob($_)}{CODE},
27 map "${_}::BUILD",
28 reverse @{mro::get_linear_isa($into)};
9aa500f6 29 join '', map qq{ ${me}->${_}(${args});\n}, @builds;
098a367b 30}
31
321;