6 use JSON::PP qw(encode_json decode_json);
9 if (my $host = $ARGV[0]) {
10 'ssh '.$host.' perl -'
16 my $pid = open2(my $out, my $in, $cmd);
23 open $jr, '<', 'jsonrepl.packed' or die "No packed repl: $!";
25 while (<$jr>) { print $in $_ }
26 print $in "__END__\n";
29 my $read = Term::ReadLine->new('REPL');
32 my $line = $read->readline('re.pl$ ');
33 exit unless defined $line;
34 next unless length $line;
35 print $in encode_json([ EVAL => $line ])."\n";
36 my $reply = decode_json scalar readline($out);
37 if ($reply->[0] eq 'MISTAKE') {
38 die "Botch: ".join(': ', @{$reply}[1,2]);
40 my $ret = $reply->[1];
43 chomp($ret->{stdout});
44 print "STDOUT:\n${\$ret->{stdout}}\n";
47 chomp($ret->{stderr});
48 print "STDERR:\n${\$ret->{stderr}}\n";