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;
+ my $value = $builder ? $instance->$builder()
+ : ref($default) eq 'CODE' ? $instance->$default()
+ : $default;
- $value = $attribute->coerce_constraint($value)
- if $attribute->should_coerce;
- $attribute->verify_against_type_constraint($value);
-
- $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;
my $buildargs = $class->_generate_BUILDARGS($metaclass);
my $processattrs = $class->_generate_processattrs($metaclass, \@attrs);
- my @compiled_constraints = map { $_->_compiled_type_constraint }
- map { $_->{type_constraint} ? $_->{type_constraint} : () } @attrs;
+ my @compiled_constraints = map { $_ ? $_->_compiled_type_constraint : undef }
+ map { $_->type_constraint } @attrs;
my $code = sprintf("#line %d %s\n", __LINE__, __FILE__).<<"...";
sub {