+++ /dev/null
-#!/usr/bin/env perl
-
-use strictures 1;
-use IPC::Open2;
-use Term::ReadLine;
-use JSON::PP qw(encode_json decode_json);
-
-my $cmd = do {
- if (my $host = $ARGV[0]) {
- 'ssh '.$host.' perl -'
- } else {
- 'perl -'
- }
-};
-
-my $pid = open2(my $out, my $in, $cmd);
-
-{
- my $jr;
- if (!eof(*DATA)) {
- $jr = \*DATA
- } else {
- open $jr, '<', 'jsonrepl.packed' or die "No packed repl: $!";
- }
- while (<$jr>) { print $in $_ }
- print $in "__END__\n";
-}
-
-my $read = Term::ReadLine->new('REPL');
-
-while (1) {
- my $line = $read->readline('re.pl$ ');
- exit unless defined $line;
- next unless length $line;
- print $in encode_json([ EVAL => $line ])."\n";
- my $reply = decode_json scalar readline($out);
- 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";
- }
-}