}
local $self->{captures} = {};
my $body = ' my $class = shift;'."\n";
+ $body .= $self->_handle_subconstructor($into, $name);
$body .= $self->_generate_args;
$body .= $self->_check_required($spec);
$body .= ' my $new = '.$self->construction_string.";\n";
;
}
+sub _handle_subconstructor {
+ my ($self, $into, $name) = @_;
+ if (my $gen = $self->{subconstructor_generator}) {
+ ' if ($class ne '.perlstring($into).') {'."\n".
+ ' '.$gen.";\n".
+ ' return $class->'.$name.'(@_)'.";\n".
+ ' }'."\n";
+ } else {
+ ''
+ }
+}
+
sub _cap_call {
my ($self, $code, $captures) = @_;
@{$self->{captures}}{keys %$captures} = values %$captures if $captures;
sub _generate_args {
my ($self) = @_;
- q{ my $args = ref($_[0]) eq 'HASH' ? $_[0] : { @_ };}."\n";
+ q{ my $args = $class->BUILDARGS(@_);}."\n";
}
sub _assign_new {
my $attr_spec = $spec->{$name};
unless ($ag->is_simple_attribute($name, $attr_spec)) {
next NAME unless defined($attr_spec->{init_arg})
- or (($attr_spec->{default} or $attr_spec->{builder})
- and not $attr_spec->{lazy});
+ or $ag->has_eager_default($name, $attr_spec);
$test{$name} = $attr_spec->{init_arg};
next NAME;
}