use strictures 1;
-use Devel::Dwarn;
use Tak::JSONChannel;
use Tak::Router;
use IPC::Open2;
use Tak::Remote;
+use Term::ReadLine;
my $pid = open2(my $out, my $in, $^X, qw(-Ilib takd))
or die "Couldn't open2 child: $!";
name => 'EVAL'
);
-::Dwarn([ $remote->blocking_request(eval => 'my $x = 1;') ]);
-::Dwarn([ $remote->blocking_request(eval => '1+$x;') ]);
+my $read = Term::ReadLine->new('REPL');
+
+while (1) {
+ my $line = $read->readline('re.pl$ ');
+ exit unless defined $line;
+ next unless length $line;
+ my $reply = [ $remote->blocking_request(eval => $line) ];
+ if ($reply->[0] eq 'MISTAKE') {
+ die "Botch: ".join(': ', @{$reply}[1,2]);
+ }
+ my $ret = $reply->[1];
+ print $ret->{return};
+ if ($ret->{stdout}) {
+ chomp($ret->{stdout});
+ print "STDOUT:\n${\$ret->{stdout}}\n";
+ }
+ if ($ret->{stderr}) {
+ chomp($ret->{stderr});
+ print "STDERR:\n${\$ret->{stderr}}\n";
+ }
+}