Remove unused methods
[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::_Utils;
9aa500f6 7use B 'perlstring';
098a367b 8
9sub generate_method {
10 my ($self, $into) = @_;
077bd026 11 quote_sub "${into}::BUILDALL", join '',
3c55a7ad 12 $self->_handle_subbuild($into),
077bd026 13 qq{ my \$self = shift;\n},
3c55a7ad 14 $self->buildall_body_for($into, '$self', '@_'),
077bd026 15 qq{ return \$self\n};
16}
17
06c4d037 18sub _handle_subbuild {
19 my ($self, $into) = @_;
20 ' if (ref($_[0]) ne '.perlstring($into).') {'."\n".
21 ' return shift->Moo::Object::BUILDALL(@_)'.";\n".
22 ' }'."\n";
23}
24
077bd026 25sub buildall_body_for {
26 my ($self, $into, $me, $args) = @_;
098a367b 27 my @builds =
28 grep *{_getglob($_)}{CODE},
29 map "${_}::BUILD",
e9adc6d3 30 reverse @{Moo::_Utils::_get_linear_isa($into)};
f82d15d5 31 join '', map qq{ ${me}->${_}(${args});\n}, @builds;
098a367b 32}
33
341;