1 package DX::ShellFrontend;
4 use Types::Standard qw(InstanceOf);
9 is => 'ro', isa => ShellSession, required => 1,
10 handles => [ qw(is_complete_command_string eval_command_string) ]
13 has session_mode => (is => 'rwp', isa => ShellMode, required => 1);
16 is => 'lazy', isa => InstanceOf['Caroline'],
17 builder => sub { Caroline->new }
20 sub BUILD { STDOUT->autoflush(1) }
25 last unless $self->rep
31 return unless defined(my $command = $self->read_command);
32 my @result = $self->eval_command_string($command);
33 $self->process_result(@result);
39 my $base_prompt = $self->session_mode eq 'shell' ? '$ ' : '? ';
40 my $rl = $self->readline;
41 return unless defined(my $command = $rl->readline($base_prompt));
42 while (not $self->is_complete_command_string($command)) {
43 $command .= $rl->readline('> ');
45 $rl->history_add($command);
50 my ($self, @result) = @_;
51 foreach my $res (@result) {
52 my ($type, $payload) = @$res;
53 $self->${\($self->can("process_${type}_result")||die)}($payload);
57 sub process_mode_result {
58 my ($self, $mode) = @_;
59 $self->_set_session_mode($mode);
62 sub process_output_result {
63 my ($self, $output) = @_;
64 $output .= "\n" unless $output =~ /\n$/;