my $key = $attribute->name;
if (defined($from) && exists($args->{$from})) {
- $args->{$from} = $attribute->coerce_constraint($args->{$from})
- if $attribute->should_coerce;
-
- $attribute->verify_against_type_constraint($args->{$from});
-
- $instance->{$key} = $args->{$from};
+ $instance->{$key} = $attribute->_coerce_and_verify($args->{$from});
weaken($instance->{$key})
if ref($instance->{$key}) && $attribute->is_weak_ref;
if ($attribute->has_trigger) {
- push @triggers_queue, [ $attribute->trigger, $args->{$from} ];
+ push @triggers_queue, [ $attribute->trigger, $instance->{$from} ];
}
}
else {
unless ($attribute->is_lazy) {
my $default = $attribute->default;
my $builder = $attribute->builder;
- my $value = $attribute->has_builder
- ? $instance->$builder
- : ref($default) eq 'CODE'
- ? $default->($instance)
- : $default;
-
- $value = $attribute->coerce_constraint($value)
- if $attribute->should_coerce;
- $attribute->verify_against_type_constraint($value);
+ my $value = $builder ? $instance->$builder()
+ : ref($default) eq 'CODE' ? $instance->$default()
+ : $default;
- $instance->{$key} = $value;
+ # XXX: we cannot use $attribute->set_value() because it invokes triggers.
+ $instance->{$key} = $attribute->_coerce_and_verify($value, $instance);;
weaken($instance->{$key})
if ref($instance->{$key}) && $attribute->is_weak_ref;