9 my ($class, $cmdline, $tag, $cb) = @_;
11 my ($uciread, $uciwrite);
12 my $pid = IPC::Open2::open2($uciread, $uciwrite, $cmdline);
14 my $ev = AnyEvent::Handle->new(
17 my ($handle, $fatal, $msg) = @_;
18 die "Error in reading from the UCI engine: $msg";
34 print $uciwrite "uci\n";
35 $ev->push_read(line => sub { $engine->_anyevent_handle_line(@_) });
40 my ($engine, $msg) = @_;
41 print { $engine->{'write'} } "$msg\n";
44 sub _anyevent_handle_line {
45 my ($engine, $handle, $line) = @_;
47 if (!$engine->{'seen_uciok'}) {
48 # Gobble up lines until we see uciok.
49 if ($line =~ /^uciok$/) {
50 $engine->{'seen_uciok'} = 1;
53 $engine->{'cb'}($engine, $line);
55 $engine->{'ev'}->push_read(line => sub { $engine->_anyevent_handle_line(@_) });