add state command for creating mutable globals
Matt S Trout [Sat, 12 Mar 2016 13:15:20 +0000 (13:15 +0000)]
lib/DX/ShellSession.pm

index fa6cb32..db3bb0b 100644 (file)
@@ -4,6 +4,7 @@ use Tcl;
 use Scalar::Util qw(weaken);
 use DX::Expander;
 use DX::Proposition;
+use DX::ActionBuilder::Normal;
 use DX::Utils qw(deparse);
 use DX::Class;
 
@@ -93,6 +94,22 @@ has tcl => (is => 'lazy', builder => sub {
       ),
     );
   });
+  $tcl->CreateCommand(state => sub {
+    my (undef, undef, undef, $name, $value) = @_;
+    my $tqs = $self->shell_state->template_query_state;
+    my $new_tqs = $tqs->but(
+      globals => $tqs->globals->with_member_at(
+        $name => DX::ActionBuilder::Normal->new(
+                   target_path => [ $name ],
+                 )->apply_to_value($self->expand_args($value)),
+      ),
+    );
+    $self->_set_shell_state(
+      $self->shell_state->but(
+        template_query_state => $new_tqs
+      ),
+    );
+  });
   $tcl->CreateCommand(trace => sub {
     my (undef, undef, undef, @trace) = @_;
     $self->_set_shell_state(