From: Matt S Trout Date: Fri, 28 Oct 2011 18:57:51 +0000 (+0000) Subject: implement repl in takc X-Git-Tag: v0.001001~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34a159d9d9bd8000f8bf9f56b19141c817dfbb89;p=scpubgit%2FTak.git implement repl in takc --- diff --git a/takc b/takc index 91745e6..d265345 100644 --- a/takc +++ b/takc @@ -1,9 +1,9 @@ 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: $!"; @@ -22,5 +22,24 @@ my $remote = Tak::Remote->new( 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"; + } +}