my $trigger = $attribute->trigger;
my $type = $attribute->type_constraint;
my $constraint = $attribute->find_type_constraint;
+ my $builder = $attribute->builder;
my $accessor = 'sub {
my $self = shift;';
if ($attribute->is_lazy) {
$accessor .= '$self->{$key} = ';
- $accessor .= ref($default) eq 'CODE'
- ? '$default->($self)'
- : '$default';
+
+ $accessor .= $attribute->has_builder
+ ? '$self->$builder'
+ : ref($default) eq 'CODE'
+ ? '$default->($self)'
+ : '$default';
+
$accessor .= ' if !exists($self->{$key});';
}
my ($self, $class, $name, %args) = @_;
confess "You must specify a default for lazy attribute '$name'"
- if $args{lazy} && !exists($args{default});
+ if $args{lazy} && !exists($args{default}) && !exists($args{builder});
confess "Trigger is not allowed on read-only attribute '$name'"
if $args{trigger} && $args{is} ne 'rw';
Creates a new code reference for each of the attribute's handles methods.
+=head2 find_type_constraint -> CODE
+
+Returns a code reference which can be used to check that a given value passes
+this attribute's type constraint;
+
+=head2 verify_type_constraint Item -> 1 | ERROR
+
+Checks that the given value passes this attribute's type constraint. Returns 1
+on success, otherwise C<confess>es.
+
=cut