$val = $self->default($instance);
} elsif (!defined $val && $self->has_builder) {
my $builder = $self->builder;
- confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'")
- unless $instance->can($builder);
- $val = $instance->$builder;
+ if($builder = $instance->can($builder)){
+ $val = $instance->$builder;
+ } else {
+ confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'");
+ }
}
if (defined $val || $self->has_default) {
}
if ( $self->has_builder ){
my $builder = $self->builder;
- confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'")
- unless $instance->can($builder);
- $self->set_value($instance, $instance->$builder);
+ if($builder = $instance->can($builder)){
+ $self->set_value($instance, $instance->$builder);
+ } else {
+ confess(blessed($instance)." does not support builder method '$builder' for attribute '" . $self->name . "'");
+ }
} else {
$self->set_value($instance, undef);
}
' $default = $attr->default(' . $inv . ') if $attr->has_default;' .
' if ( $attr->has_builder ) { '.
' my $builder = $self->builder;'.
- ' confess(blessed('.$inv.')." does not support builder method \'$builder\' for attribute \'" . $attr->name . "\'")'.
- ' unless '.$inv.'->can($builder); '.
- ' $default = '.$inv.'->$builder;'.
+ ' if($builder = '.$inv.'->can($builder)){ '.
+ ' $default = '.$inv.'->$builder; '.
+ ' } else { '.
+ ' confess(blessed('.$inv.')." does not support builder method \'$builder\' for attribute \'" . $attr->name . "\'");'.
+ ' }'.
' }'.
($attr->should_coerce
? '$default = $attr->type_constraint->coerce($default);'
return 'unless (exists ' . $slot_access . ') {' .
' if ($attr->has_default) { ' . $slot_access . ' = $attr->default(' . $inv . '); }' .
- ' elsif ($attr->has_builder) { my $builder = $attr->builder; ' . $slot_access . ' = ' . $inv . '->$builder; }' .
- ' else { ' .$slot_access . ' = undef; } '.
+ ' elsif ($attr->has_builder) { '.
+ ' my $builder = $attr->builder; ' .
+ ' if($builder = '.$inv.'->can($builder)){ '.
+ ' ' . $slot_access . ' = ' . $inv . '->$builder; '.
+ ' } else { '.
+ ' confess(blessed('.$inv.')." does not support builder method \'$builder\' for attribute \'" . $attr->name . "\'");'.
+ ' }'.
+ ' } else { ' .$slot_access . ' = undef; } '.
'}';
}