Commit | Line | Data |
60cda014 |
1 | package DX::Var; |
2 | |
3 | use Moo; |
4 | |
5 | has id => (is => 'ro', required => 1); |
6 | |
7 | has bound_stream => (is => 'ro'); |
8 | |
b373788e |
9 | has 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 |
17 | has action => (is => 'ro'); |
18 | |
b373788e |
19 | sub is_bound { |
20 | my ($self) = @_; |
21 | $self->has_bound_value || $self->bound_stream; |
22 | } |
23 | |
60cda014 |
24 | sub with_stream { |
25 | my ($self, $stream) = @_; |
26 | $self->new(%$self, bound_stream => $stream); |
27 | } |
28 | |
b40d5c51 |
29 | sub with_value { |
30 | my ($self, $stream) = @_; |
31 | $self->new(%$self, bound_value => $stream); |
32 | } |
33 | |
71217e42 |
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 | |
60cda014 |
44 | 1; |