Commit | Line | Data |
36cf3bcb |
1 | use strictures 1; |
36cf3bcb |
2 | use Tak::JSONChannel; |
3 | use Tak::Router; |
4 | use IPC::Open2; |
5 | use Tak::Remote; |
34a159d9 |
6 | use Term::ReadLine; |
36cf3bcb |
7 | |
8 | my $pid = open2(my $out, my $in, $^X, qw(-Ilib takd)) |
9 | or die "Couldn't open2 child: $!"; |
10 | |
11 | my $channel = Tak::JSONChannel->new( |
12 | read_fh => $out, |
13 | write_fh => $in |
14 | ); |
15 | |
16 | my $router = Tak::Router->new( |
17 | channel => $channel, |
18 | ); |
19 | |
20 | my $remote = Tak::Remote->new( |
21 | router => $router, |
22 | name => 'EVAL' |
23 | ); |
24 | |
34a159d9 |
25 | my $read = Term::ReadLine->new('REPL'); |
26 | |
27 | while (1) { |
28 | my $line = $read->readline('re.pl$ '); |
29 | exit unless defined $line; |
30 | next unless length $line; |
31 | my $reply = [ $remote->blocking_request(eval => $line) ]; |
32 | if ($reply->[0] eq 'MISTAKE') { |
33 | die "Botch: ".join(': ', @{$reply}[1,2]); |
34 | } |
35 | my $ret = $reply->[1]; |
36 | print $ret->{return}; |
37 | if ($ret->{stdout}) { |
38 | chomp($ret->{stdout}); |
39 | print "STDOUT:\n${\$ret->{stdout}}\n"; |
40 | } |
41 | if ($ret->{stderr}) { |
42 | chomp($ret->{stderr}); |
43 | print "STDERR:\n${\$ret->{stderr}}\n"; |
44 | } |
45 | } |