bind_var_then -> bind_value
[scpubgit/DKit.git] / lib / DX / Var.pm
CommitLineData
60cda014 1package DX::Var;
2
3use Moo;
4
5has id => (is => 'ro', required => 1);
6
7has bound_stream => (is => 'ro');
8
b373788e 9has bound_value => (is => 'lazy', predicate => 1, clearer => 1, builder => sub {
71217e42 10 if (defined(my $next = $_[0]->bound_stream->next)) {
11 return $next;
12 }
13 DX::State->return_from_op('backtrack');
14 return;
60cda014 15});
16
71217e42 17has action => (is => 'ro');
18
b373788e 19sub is_bound {
20 my ($self) = @_;
21 $self->has_bound_value || $self->bound_stream;
22}
23
60cda014 24sub with_stream {
25 my ($self, $stream) = @_;
26 $self->new(%$self, bound_stream => $stream);
27}
28
b40d5c51 29sub with_value {
30 my ($self, $stream) = @_;
31 $self->new(%$self, bound_value => $stream);
32}
33
71217e42 34sub with_action {
35 my ($self, $action) = @_;
36 $self->new(%$self, action => $action);
37}
38
39sub copy {
40 my ($self) = @_;
41 ref($self)->new(%$self);
42}
43
60cda014 441;