1 package DX::ShellFrontend;
3 use Types::Standard qw(Enum);
9 is => 'ro', isa => ShellSession, required => 1,
10 handles => [ qw(is_complete_command_string eval_command_string) ]
13 has session_mode => (is => 'rwp', isa => Enum['shell','query'], required => 1);
15 has readline => (is => 'lazy', builder => sub { Caroline->new });
17 sub BUILD { STDOUT->autoflush(1) }
22 last unless $self->rep
28 return unless defined(my $command = $self->read_command);
29 my @result = $self->eval_command_string($command);
30 $self->process_result(@result);
36 my $base_prompt = $self->session_mode eq 'shell' ? '$ ' : '? ';
37 my $rl = $self->readline;
38 return unless defined(my $command = $rl->readline($base_prompt));
39 while (not $self->is_complete_command_string($command)) {
40 $command .= $rl->readline('> ');
42 $rl->history_add($command);
47 my ($self, @result) = @_;
48 foreach my $res (@result) {
49 my ($type, $payload) = @$res;
50 $self->${\($self->can("process_${type}_result")||die)}($payload);
54 sub process_mode_result {
55 my ($self, $mode) = @_;
56 $self->_set_session_mode($mode);
59 sub process_output_result {
60 my ($self, $output) = @_;
61 $output .= "\n" unless $output =~ /\n$/;