refactor constructor generation and test more complex cases
[gitmo/Moo.git] / lib / Method / Generate / BuildAll.pm
CommitLineData
098a367b 1package Method::Generate::BuildAll;
2
3use strictures 1;
4use base qw(Class::Tiny::Object);
5use Sub::Quote;
6use Class::Tiny::_mro;
7use Class::Tiny::_Utils;
8
9sub generate_method {
10 my ($self, $into) = @_;
077bd026 11 quote_sub "${into}::BUILDALL", join '',
12 qq{ my \$self = shift;\n},
13 $self->buildall_body_for($into, '$self', '@_'),
14 qq{ return \$self\n};
15}
16
17sub buildall_body_for {
18 my ($self, $into, $me, $args) = @_;
098a367b 19 my @builds =
20 grep *{_getglob($_)}{CODE},
21 map "${_}::BUILD",
22 reverse @{mro::get_linear_isa($into)};
077bd026 23 join '', map qq{ ${me}->${_}(${args});\n}, @builds;
098a367b 24}
25
261;