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";
36 print $uciwrite "uci\n";
37 $ev->push_read(line => sub { $engine->_anyevent_handle_line(@_) });
42 my ($engine, $msg) = @_;
43 print { $engine->{'write'} } "$msg\n";
46 sub _anyevent_handle_line {
47 my ($engine, $handle, $line) = @_;
49 if (!$engine->{'seen_uciok'}) {
50 # Gobble up lines until we see uciok.
51 if ($line =~ /^id (\S+) (.*?)\s*$/) {
52 $engine->{'id'}->{$1} = $2;
53 } elsif ($line =~ /^uciok$/) {
54 $engine->{'seen_uciok'} = 1;
57 $engine->{'cb'}($engine, $line);
59 $engine->{'ev'}->push_read(line => sub { $engine->_anyevent_handle_line(@_) });