add but method to state
[scpubgit/DKit.git] / lib / DX / State.pm
index 4815ab2..2bf0f07 100644 (file)
@@ -23,7 +23,7 @@ sub bind_stream_then {
   my ($self, $var, $stream, $then) = @_;
   warn "Binding ".$var->id." to $stream";
   my $bound = $var->with_stream($stream);
-  $self->new(%$self,
+  $self->but(
     by_id => { %{$self->by_id}, $var->id => $bound },
     next_op => $then
   )->mark_choice($bound);
@@ -31,9 +31,7 @@ sub bind_stream_then {
 
 sub mark_choice {
   my ($self, $var) = @_;
-  $self->new(%$self,
-    last_choice => [ $self, $var ]
-  );
+  $self->but(last_choice => [ $self, $var ]);
 }
 
 sub backtrack {
@@ -51,7 +49,7 @@ sub backtrack {
 
 sub then {
   my ($self, $then) = @_;
-  $self->new(%$self, next_op => $then);
+  $self->but(next_op => $then);
 }
 
 sub run {
@@ -70,4 +68,9 @@ sub push_backtrack {
   $_[0]->then(DX::Op::FromCode->new(code => sub { $_[1]->backtrack }));
 }
 
+sub but {
+  my ($self, @but) = @_;
+  $self->new(%$self, @but);
+}
+
 1;