From: Matt S Trout Date: Sat, 12 Mar 2016 13:15:20 +0000 (+0000) Subject: add state command for creating mutable globals X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bc0773eb68361b8104c9f626fd79ede831ef761e;p=scpubgit%2FDX.git add state command for creating mutable globals --- diff --git a/lib/DX/ShellSession.pm b/lib/DX/ShellSession.pm index fa6cb32..db3bb0b 100644 --- a/lib/DX/ShellSession.pm +++ b/lib/DX/ShellSession.pm @@ -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(