my $self = shift;
my ($attr, $idx) = @_;
- my $default = $self->_inline_default_value($attr, $idx);
-
if (defined(my $init_arg = $attr->init_arg)) {
my @source = (
'if (exists $params->{\'' . $init_arg . '\'}) {',
- $attr->_inline_set_value(
- '$instance', '$params->{\'' . $init_arg . '\'}'
- ),
+ $self->_inline_init_attr_from_constructor($attr, $idx),
'}',
);
- if (defined $default) {
+ if (my @default = $self->_inline_init_attr_from_default($attr, $idx)) {
push @source, (
'else {',
- $attr->_inline_set_value('$instance', $default),
+ @default,
'}',
);
}
return @source;
}
- elsif (defined $default) {
- return $attr->_inline_set_value('$instance', $default);
+ elsif (my @default = $self->_inline_init_attr_from_default($attr, $idx)) {
+ return (
+ '{',
+ @default,
+ '}',
+ );
}
else {
return ();
}
}
+sub _inline_init_attr_from_constructor {
+ my $self = shift;
+ my ($attr, $idx) = @_;
+
+ return $attr->_inline_set_value(
+ '$instance', '$params->{\'' . $attr->init_arg . '\'}'
+ ),
+}
+
+sub _inline_init_attr_from_default {
+ my $self = shift;
+ my ($attr, $idx) = @_;
+
+ my $default = $self->_inline_default_value($attr, $idx);
+ return unless $default;
+
+ return $attr->_inline_set_value('$instance', $default);
+}
+
sub _inline_default_value {
my $self = shift;
my ($attr, $index) = @_;
_inline_new_object _inline_default_value _inline_preserve_weak_metaclasses
_inline_slot_initializer _inline_extra_init _inline_fallback_constructor
_inline_generate_instance _inline_params _inline_slot_initializers
+ _inline_init_attr_from_constructor _inline_init_attr_from_default
_generate_fallback_constructor
construct_instance _construct_instance
construct_class_instance _construct_class_instance