1 package DX::ShellSession;
4 use Scalar::Util qw(weaken);
8 has shell_state => (is => 'rwp', required => 1, isa => ShellState);
11 is => 'lazy', builder => sub { DX::Expander->new(tcl => $_[0]->tcl) },
12 handles => [ qw(expand_args) ],
15 has tcl => (is => 'lazy', builder => sub {
19 $tcl->CreateCommand('?' => sub {
20 $self->apply_to_state([ 'new_query_state' ], [ mode => 'query' ])
22 $tcl->CreateCommand('?+' => sub {
23 $self->apply_to_state([ mode => 'query' ])
25 $tcl->CreateCommand('.' => sub {
26 $self->apply_to_state([ mode => 'shell' ])
29 keys %{$self->shell_state->template_query_state->predicates}
31 $tcl->CreateCommand($pred => sub {
32 my (undef, undef, undef, @args) = @_; # ($data, $interp, $pred)
33 $self->apply_predicate($pred => @args);
40 my ($self, @to_apply) = @_;
41 my $state = $self->shell_state;
43 foreach my $to_apply (@to_apply) {
44 my ($change, @args) = @$to_apply;
45 ($state, my @this_result) = $state->${\"with_${change}"}(@args);
46 push @Result, @this_result;
48 $self->_set_shell_state($state);
52 sub is_complete_command_string {
53 my ($self, $string) = @_;
54 return !!$self->tcl->icall(info => complete => $string);
57 sub eval_command_string {
58 my ($self, $string) = @_;
61 $self->tcl->Eval($string);
63 push @Result, [ output => $_ ];
69 my ($self, $pred, @args) = @_;
70 die "Can't call predicate ${pred} outside a query\n"
71 unless $self->shell_state->mode eq 'query';
72 use Data::Dumper::Concise; die Dumper [ $pred, $self->expand_args(@args) ];