my $instance = bless {}, $self->name;
+ my @triggers_queue;
+
foreach my $attribute ($self->get_all_attributes) {
my $from = $attribute->init_arg;
my $key = $attribute->name;
if ref($instance->{$key}) && $attribute->is_weak_ref;
if ($attribute->has_trigger) {
- $attribute->trigger->($instance, $args{$from});
+ push @triggers_queue, [ $attribute->trigger, $args{$from} ];
}
}
else {
}
}
}
+
+ foreach my $trigger_and_value(@triggers_queue){
+ my($trigger, $value) = @{$trigger_and_value};
+ $trigger->($instance, $value);
+ }
+
return $instance;
}
...
local $@;
- # warn $code;
+ #warn $code;
my $res = eval $code;
die $@ if $@;
$res;
}
$code .= "
\$attrs[$index]->verify_type_constraint_error(
- '$key', \$value, \$attrs[$index]->type_constraint
+ q{$key}, \$value, \$attrs[$index]->type_constraint
)
}
";
}
- $code .= "\$instance->{'$key'} = \$value;\n";
+ $code .= "\$instance->{q{$key}} = \$value;\n";
if ($attr->is_weak_ref) {
- $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n";
+ $code .= "Scalar::Util::weaken( \$instance->{q{$key}} ) if ref( \$value );\n";
}
if ($attr->has_trigger) {
- $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value );\n";
+ $code .= "push \@triggers, [\$attrs[$index]->{trigger}, \$value];\n";
}
$code .= "\n} else {\n";
if ($attr->has_type_constraint) {
$code .= "{
unless (\$attrs[$index]->{type_constraint}->check(\$value)) {
- \$attrs[$index]->verify_type_constraint_error('$key', \$value, \$attrs[$index]->type_constraint)
+ \$attrs[$index]->verify_type_constraint_error(q{$key}, \$value, \$attrs[$index]->type_constraint)
}
}";
}
- $code .= "\$instance->{'$key'} = \$value;\n";
+ $code .= "\$instance->{q{$key}} = \$value;\n";
if ($attr->is_weak_ref) {
- $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n";
+ $code .= "Scalar::Util::weaken( \$instance->{q{$key}} ) if ref( \$value );\n";
}
}
}
push @res, $code;
}
- return join "\n", @res;
+ return join "\n", q{my @triggers;}, @res, q{$_->[0]->($instance, $_->[1]) for @triggers;};
}
sub _generate_BUILDARGS {