Alt-CWB-ambs
view release on metacpan or search on metacpan
lib/CWB/CQP.pm view on Meta::CPAN
=head1 DESCRIPTION
A B<CWB::CQP> object represents an instance of the corpus query processor CQP
running as a background process. By calling suitable methods on this object,
arbitrary CQP commands can be executed and their output can be captured.
The C<STDERR> stream of the CQP process is monitored for error messages,
which can automatically trigger an error handler.
Every B<CWB::CQP> object has its own CQP background process and communication is
fully asynchronous. This enables scripts to perform other actions while a long
CQP command is executing, or to run multiple CQP instances in parallel.
=cut
use warnings;
use strict;
use sigtrap qw(die PIPE); # catch write errors to background CQP process
## $SIG{'CHLD'} = 'IGNORE'; # it would be nice to reap child processes automatically, but this seems to mess up closing pipes
lib/CWB/CQP.pm view on Meta::CPAN
push @{$self->{'error_message'}}, split /\n/, $stderr_buffer; # append output on stderr to error message
$self->error(@{$self->{'error_message'}}); # may call error handler and abort, or print message and continue
}
return $lines;
}
=item I<$cqp>->B<run>(I<$cmd>);
Start a single CQP command I<$cmd> in the background. This method returns immediately.
Command output can then be read with the B<getline>, B<getlines> and B<getrow> methods.
If asynchronous communication is desired, use B<ready> to check whether output is available.
It is an error to B<run> a new command before the output of the previous command has completely
been processed.
=cut
sub run {
croak 'USAGE: $cqp->run($cmd]);'
unless @_ == 2;
my $self = shift;
t/31_cqp_dickens.t.dont_run view on Meta::CPAN
if ($r1->[0] != $r2->[0] or
$r1->[1] != $r2->[1] or
$r1->[2] != $r2->[2] or
$r2->[3] != -1) {
print "\n!! returned row #".($i+1)." [@$r2] differs from undumped table [@$r1]\n";
exit 1;
}
}
print "ok\n";
# step 22: test asynchronous execution
print " - testing asynchronous command execution ... ";
$dickens_found = 0;
$CQP->run("show corpora");
while (defined($_ = $CQP->getline)) {
$dickens_found = 1 if /^DICKENS$/
}
if (not $dickens_found) {
print "\n!! corpus DICKENS not found in output of 'show corpora'\n";
exit 1;
}
print "ok\n";
( run in 0.244 second using v1.01-cache-2.11-cpan-0d8aa00de5b )