Yes, if you remove the possibility of infinite recursion by checking that at least one of these values ββis specified:
has start => ( ... predicate => 'has_start', ); has end => ( ... predicate => 'has_end', ); sub BUILD { my $self = shift; die "Need to specify at least one of 'start', 'end'!" if not $self->has_start and not $self->has_end; }
Alternatively, you can defer the check for subusers by default:
has start => ( ... predicate => 'has_start', default => sub { my $self = shift; die "Need to specify at least one of 'start', 'end'!" if not $self->has_end; $self->end; }, ); has end => ( ... predicate => 'has_end', default => sub { my $self = shift; die "Need to specify at least one of 'start', 'end'!" if not $self->has_start; $self->start; }, );
source share