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