CQI/IOClient.pm

filter: Statementstmt 5.1% 25 / 489 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 63 MC/DCmcdc 0.0% 0 / 34 Subroutinesub 8.9% 7 / 78 Podpod 0.0% 0 / 71 totaltotal 3.7% 32 / 849 SCAR 86.6
CC
80
Cov
4%
cqi_fdist
132.0
cqi_query
72.0
cqi_connect
42.0
CRAP 5786.0
↑ Summary CQI/Client.pm »
1 package CWB::CQI::IOClient;
2 # -*-cperl-*-
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use CWB::CQI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use IO::Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # export CQi client functions
13 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 our @EXPORT = (
15 qw<cqi_connect cqi_bye cqi_ask_feature>,
16 qw<cqi_list_corpora cqi_charset cqi_properties cqi_attributes cqi_structural_attribute_has_values cqi_full_name cqi_corpus_info cqi_drop_corpus>,
17 qw<cqi_attribute_size cqi_lexicon_size cqi_drop_attribute cqi_str2id cqi_id2str cqi_id2freq cqi_cpos2id cqi_cpos2str cqi_cpos2struc cqi_cpos2lbound cqi_cpos2rbound cqi_cpos2alg cqi_struc2str cqi_id2cpos cqi_idlist2cpos cqi_regex2id cqi_struc2cpos cqi_alg2cpos>,
18 qw<cqi_query cqi_list_subcorpora cqi_subcorpus_size cqi_subcorpus_has_field cqi_dump_subcorpus cqi_drop_subcorpus cqi_fdist>,
19 );
20  
21 =head1 NAME
22  
23 CWB::CQI::IOClient - Alternative CQi client library (based on IO::Socket)
24  
25  
26 =head1 DESCRIPTION
27  
28 This is an alternative version of the B<CWB::CQI::Client> library, which uses the object-oriented
29 B<IO::Socket> module instead of calling low-level socket functions. It is a direct replacement and
30 presents exactly the same API, so one can simply change
31  
32 use CWB::CQI::Client;
33  
34 to
35  
36 use CWB::CQI::IOClient;
37  
38 in any CQi client script. See the L<CWB::CQI::Client> manpage for more information and a description
39 of available CQi functions.
40  
41 =cut
42  
43  
44 2 our $conn = new FileHandle;
45  
46 #
47 #
48 # Error Handling
49 #
50 #
51  
52 2 our $LastCmd = "<none>"; # keep track of last command in case we receive an error code
53  
54 sub CqiError (@) {
55 0 ▶ foreach (@_) {
Subroutine CqiError: not called CC=2 SCAR=17.9
Pod undocumented
56 0 print STDERR "CQi ERROR: $_\n";
57 }
58 0 croak "CQI::Client -- connection aborted.";
59 0 exit 1; # Perl/Tk seems to catch the croak ...
60 }
61  
62 sub CqiErrorCode ($) {
63 0 ▶ my $errcode = shift;
Subroutine CqiErrorCode: not called CC=2 SCAR=17.9
Pod undocumented
64 0 my $group = $errcode >> 8;
65 0 my $command = $errcode & 0xff;
66 0 my $errhex = sprintf "%02X:%02X", $group, $command;
67 0 my $name = $CWB::CQI::CommandName{$errcode};
68
69 0 ▶ if ($name =~ /ERROR/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /ERROR/) { } 0 0 0
70 0 CqiError "Received $name [$errhex] in response to", "$LastCmd";
71 }
72 else {
73 0 CqiError "Unexpected response $name [$errhex] to", "$LastCmd";
74 }
75 }
76  
77 sub CqiCheckResponse ($@) {
78 0 ▶ my $response = shift;
Subroutine CqiCheckResponse: not called CC=2 SCAR=17.9
Pod undocumented
79 0 my %expect = map { $_ => 1 } @_;
80
81 CqiErrorCode $response
82 0 ▶ unless defined $expect{$response};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $expect{$response} 0 0 0
83 }
84  
85  
86 #
87 #
88 # Connect to CQi server / Disconnect
89 #
90 #
91  
92 sub cqi_connect {
93 0 ▶ my $user = shift;
Subroutine cqi_connect: not called CC=6 SCAR=37.4
Pod undocumented
94 0 my $passwd = shift;
95 0 my $host = shift; # optional
96 0 my $port = shift; # optional
97  
98 0 ▶ $host = 'localhost'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 0 0
99 unless defined $host;
100 0 ▶ $port = $CWB::CQI::PORT
Branch: 1 branch
BranchTrueFalseTotal
unless defined $port 0 0 0
101 unless defined $port;
102  
103 0 ▶ croak "USAGE: cqi_connect(username, password, [, remotehost [, port]]);"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $user and defined $passwd 0 0 0
Condition0%0/3
defined $user and defined $passwd
!ll&&!rl&&r
000
MC/DC0%0/2
defined $user and defined $passwd
defined $user defined $passwd
Truth table0%0/3
A and B
A= defined $userB= defined $passwd
ABresult
0X0
100
111
104 unless defined $user and defined $passwd;
105 0 $LastCmd = "CQI_CTRL_CONNECT($user, '$passwd', $host, $port)";
106  
107 0 my $ipaddr = inet_aton($host);
108 0 my $sockaddr = sockaddr_in($port, $ipaddr);
109 0 my $protocol = getprotobyname('tcp');
110  
111 $conn = new IO::Socket 'Domain' => AF_INET, 'Type' => SOCK_STREAM, 'Proto' => "tcp", 'PeerHost' => $host, 'PeerPort' => $port
112 0 ▶ or do { croak "cqi_connect(): $!", exit 1};
Branch: 1 branch
BranchTrueFalseTotal
$CWB::CQI::IOClient::conn = "IO::Socket"->new("Domain", 2, "Type", 1, "Proto", "tcp", "PeerHost", $host, "PeerPort", $port) or do { croak("cqi_connect(): $!", exit 1) } 0 0 0
113 0 $conn->autoflush(0);
114  
115 0 cqi_send_word($CWB::CQI::CTRL_CONNECT);
116 0 cqi_send_string($user);
117 0 cqi_send_string($passwd);
118 0 cqi_flush();
119  
120 0 my $response = cqi_read_word();
121 0 CqiCheckResponse $response, $CWB::CQI::STATUS_CONNECT_OK;
122 }
123  
124 sub cqi_bye {
125 0 ▶ $LastCmd = "CQI_CTRL_BYE()";
Subroutine cqi_bye: not called CC=1 SCAR=6.9
Pod undocumented
126 0 cqi_send_word($CWB::CQI::CTRL_BYE);
127 0 cqi_flush();
128 0 my $response = cqi_read_word();
129 0 CqiCheckResponse $response, $CWB::CQI::STATUS_BYE_OK;
130 0 $conn->close;
131 0 $conn = undef;
132 }
133  
134 sub cqi_ping {
135 0 ▶ $LastCmd = "CQI_CTRL_PING()";
Subroutine cqi_ping: not called CC=1 SCAR=6.9
Pod undocumented
136 0 cqi_send_word($CWB::CQI::CTRL_PING);
137 0 cqi_flush();
138 0 CqiCheckResponse cqi_read_word(), $CWB::CQI::STATUS_PING_OK;
139 }
140  
141  
142 #
143 #
144 # CQi Commands
145 #
146 #
147  
148 sub cqi_ask_feature {
149 0 ▶ my $feature = lc shift;
Subroutine cqi_ask_feature: not called CC=2 SCAR=17.9
Pod undocumented
150 0 my %features = (
151 "cqi1.0" => $CWB::CQI::ASK_FEATURE_CQI_1_0,
152 "cl2.3" => $CWB::CQI::ASK_FEATURE_CL_2_3,
153 "cqp2.3" => $CWB::CQI::ASK_FEATURE_CQP_2_3,
154 );
155 croak "USAGE: \$supported = cqi_ask_feature('cqi1.0' | 'cl2.3' | 'cqp2.3');"
156 0 ▶ unless defined $features{$feature};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $features{$feature} 0 0 0
157 0 $LastCmd = $CWB::CQI::CommandName{$features{$feature}} . "()";
158 0 cqi_send_word($features{$feature});
159 0 cqi_flush();
160 0 return cqi_expect_bool();
161 }
162  
163 sub cqi_list_corpora {
164 0 ▶ $LastCmd = "CQI_CORPUS_LIST_CORPORA()";
Subroutine cqi_list_corpora: not called CC=2 SCAR=17.9
Pod undocumented
165 0 ▶ croak "USAGE: \@corpora = cqi_list_corpora();"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 0 0 0
166 unless @_ == 0;
167 0 cqi_send_word($CWB::CQI::CORPUS_LIST_CORPORA);
168 0 cqi_flush();
169 0 return cqi_expect_string_list();
170 }
171  
172 sub cqi_charset {
173 0 ▶ my $corpus = shift;
Subroutine cqi_charset: not called CC=1 SCAR=6.9
Pod undocumented
174 0 $LastCmd = "CQI_CORPUS_CHARSET($corpus)";
175 0 cqi_send_word($CWB::CQI::CORPUS_CHARSET);
176 0 cqi_send_string($corpus);
177 0 cqi_flush();
178 0 return cqi_expect_string();
179 }
180  
181 sub cqi_properties {
182 0 ▶ my $corpus = shift;
Subroutine cqi_properties: not called CC=1 SCAR=6.9
Pod undocumented
183 0 $LastCmd = "CQI_CORPUS_PROPERTIES($corpus)";
184 0 cqi_send_word($CWB::CQI::CORPUS_PROPERTIES);
185 0 cqi_send_string($corpus);
186 0 cqi_flush();
187 0 return cqi_expect_string_list();
188 }
189  
190 sub cqi_attributes {
191 0 ▶ my $corpus = shift;
Subroutine cqi_attributes: not called CC=2 SCAR=17.9
Pod undocumented
192 0 my $type = shift;
193 0 my %types = (
194 'p' => $CWB::CQI::CORPUS_POSITIONAL_ATTRIBUTES,
195 's' => $CWB::CQI::CORPUS_STRUCTURAL_ATTRIBUTES,
196 'a' => $CWB::CQI::CORPUS_ALIGNMENT_ATTRIBUTES,
197 );
198 croak "USAGE: \@attributes = cqi_attributes(\$corpus, ('p'|'s'|'a'));"
199 0 ▶ unless defined $types{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $types{$type} 0 0 0
200 0 $LastCmd = $CWB::CQI::CommandName{$types{$type}} . "($corpus)";
201 0 cqi_send_word($types{$type});
202 0 cqi_send_string($corpus);
203 0 cqi_flush();
204 0 return cqi_expect_string_list();
205 }
206  
207 sub cqi_structural_attribute_has_values {
208 0 ▶ my $attribute = shift;
Subroutine cqi_structural_attribute_has_values: not called CC=1 SCAR=6.9
Pod undocumented
209 0 $LastCmd = "CQI_CORPUS_STRUCTURAL_ATTRIBUTE_HAS_VALUES($attribute)";
210 0 cqi_send_word($CWB::CQI::CORPUS_STRUCTURAL_ATTRIBUTE_HAS_VALUES);
211 0 cqi_send_string($attribute);
212 0 cqi_flush();
213 0 return cqi_expect_bool();
214 }
215  
216 sub cqi_full_name {
217 0 ▶ my $corpus = shift;
Subroutine cqi_full_name: not called CC=1 SCAR=6.9
Pod undocumented
218 0 $LastCmd = "CQI_CORPUS_FULL_NAME($corpus)";
219 0 cqi_send_word($CWB::CQI::CORPUS_FULL_NAME);
220 0 cqi_send_string($corpus);
221 0 cqi_flush();
222 0 return cqi_expect_string();
223 }
224  
225 sub cqi_corpus_info {
226 0 ▶ my $corpus = shift;
Subroutine cqi_corpus_info: not called CC=1 SCAR=6.9
Pod undocumented
227 0 $LastCmd = "CQI_CORPUS_INFO($corpus)";
228 0 cqi_send_word($CWB::CQI::CORPUS_INFO);
229 0 cqi_send_string($corpus);
230 0 cqi_flush();
231 0 return cqi_expect_string_list();
232 }
233  
234 sub cqi_drop_corpus {
235 0 ▶ my $corpus = shift;
Subroutine cqi_drop_corpus: not called CC=1 SCAR=6.9
Pod undocumented
236 0 $LastCmd = "CQI_CORPUS_DROP_CORPUS($corpus)";
237 0 cqi_send_word($CWB::CQI::CORPUS_DROP_CORPUS);
238 0 cqi_send_string($corpus);
239 0 cqi_flush();
240 0 cqi_expect_status($CWB::CQI::STATUS_OK);
241 }
242  
243 sub cqi_attribute_size {
244 0 ▶ my $attribute = shift;
Subroutine cqi_attribute_size: not called CC=1 SCAR=6.9
Pod undocumented
245 0 $LastCmd = "CQI_CL_ATTRIBUTE_SIZE($attribute)";
246 0 cqi_send_word($CWB::CQI::CL_ATTRIBUTE_SIZE);
247 0 cqi_send_string($attribute);
248 0 cqi_flush();
249 0 return cqi_expect_int();
250 }
251  
252 sub cqi_lexicon_size {
253 0 ▶ my $attribute = shift;
Subroutine cqi_lexicon_size: not called CC=1 SCAR=6.9
Pod undocumented
254 0 $LastCmd = "CQI_CL_LEXICON_SIZE($attribute)";
255 0 cqi_send_word($CWB::CQI::CL_LEXICON_SIZE);
256 0 cqi_send_string($attribute);
257 0 cqi_flush();
258 0 return cqi_expect_int();
259 }
260  
261 sub cqi_drop_attribute {
262 0 ▶ my $attribute = shift;
Subroutine cqi_drop_attribute: not called CC=1 SCAR=6.9
Pod undocumented
263 0 $LastCmd = "CQI_CL_DROP_ATTRIBUTE($attribute)";
264 0 cqi_send_word($CWB::CQI::CL_DROP_ATTRIBUTE);
265 0 cqi_send_string($attribute);
266 0 cqi_flush();
267 0 cqi_expect_status($CWB::CQI::STATUS_OK);
268 }
269  
270 # 'scalar' functions which map to lists in the CQi are wrapped
271 # in a scalar-safe client interface, so we CAN use them with simple
272 # scalars in CQI::Client.
273 sub cqi_str2id {
274 0 ▶ my $attribute = shift;
Subroutine cqi_str2id: not called CC=3 SCAR=24.8
Pod undocumented
275 0 $LastCmd = "CQI_CL_STR2ID($attribute, [@_])";
276 0 cqi_send_word($CWB::CQI::CL_STR2ID);
277 0 cqi_send_string($attribute);
278 0 cqi_send_string_list(@_);
279 0 cqi_flush();
280 0 my @list = cqi_expect_int_list();
281 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
282 0 return @list;
283 }
284 else {
285 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
286 0 return $list[0];
287 }
288 }
289  
290 sub cqi_id2str {
291 0 ▶ my $attribute = shift;
Subroutine cqi_id2str: not called CC=3 SCAR=24.8
Pod undocumented
292 0 $LastCmd = "CQI_CL_ID2STR($attribute, [@_])";
293 0 cqi_send_word($CWB::CQI::CL_ID2STR);
294 0 cqi_send_string($attribute);
295 0 cqi_send_int_list(@_);
296 0 cqi_flush();
297 0 my @list = cqi_expect_string_list();
298 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
299 0 return @list;
300 }
301 else {
302 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
303 0 return $list[0];
304 }
305 }
306  
307 sub cqi_id2freq {
308 0 ▶ my $attribute = shift;
Subroutine cqi_id2freq: not called CC=3 SCAR=24.8
Pod undocumented
309 0 $LastCmd = "CQI_CL_ID2FREQ($attribute, [@_])";
310 0 cqi_send_word($CWB::CQI::CL_ID2FREQ);
311 0 cqi_send_string($attribute);
312 0 cqi_send_int_list(@_);
313 0 cqi_flush();
314 0 my @list = cqi_expect_int_list();
315 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
316 0 return @list;
317 }
318 else {
319 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
320 0 return $list[0];
321 }
322 }
323  
324 sub cqi_cpos2id {
325 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2id: not called CC=3 SCAR=24.8
Pod undocumented
326 0 $LastCmd = "CQI_CL_CPOS2ID($attribute, [@_])";
327 0 cqi_send_word($CWB::CQI::CL_CPOS2ID);
328 0 cqi_send_string($attribute);
329 0 cqi_send_int_list(@_);
330 0 cqi_flush();
331 0 my @list = cqi_expect_int_list();
332 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
333 0 return @list;
334 }
335 else {
336 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
337 0 return $list[0];
338 }
339 }
340  
341 sub cqi_cpos2str {
342 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2str: not called CC=3 SCAR=24.8
Pod undocumented
343 0 $LastCmd = "CQI_CL_CPOS2STR($attribute, [@_])";
344 0 cqi_send_word($CWB::CQI::CL_CPOS2STR);
345 0 cqi_send_string($attribute);
346 0 cqi_send_int_list(@_);
347 0 cqi_flush();
348 0 my @list = cqi_expect_string_list();
349 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
350 0 return @list;
351 }
352 else {
353 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
354 0 return $list[0];
355 }
356 }
357  
358 sub cqi_cpos2struc {
359 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2struc: not called CC=3 SCAR=24.8
Pod undocumented
360 0 $LastCmd = "CQI_CL_CPOS2STRUC($attribute, [@_])";
361 0 cqi_send_word($CWB::CQI::CL_CPOS2STRUC);
362 0 cqi_send_string($attribute);
363 0 cqi_send_int_list(@_);
364 0 cqi_flush();
365 0 my @list = cqi_expect_int_list();
366 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
367 0 return @list;
368 }
369 else {
370 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
371 0 return $list[0];
372 }
373 }
374  
375 sub cqi_cpos2lbound {
376 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2lbound: not called CC=3 SCAR=24.8
Pod undocumented
377 0 $LastCmd = "CQI_CL_CPOS2LBOUND($attribute, [@_])";
378 0 cqi_send_word($CWB::CQI::CL_CPOS2LBOUND);
379 0 cqi_send_string($attribute);
380 0 cqi_send_int_list(@_);
381 0 cqi_flush();
382 0 my @list = cqi_expect_int_list();
383 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
384 0 return @list;
385 }
386 else {
387 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
388 0 return $list[0];
389 }
390 }
391  
392 sub cqi_cpos2rbound {
393 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2rbound: not called CC=3 SCAR=24.8
Pod undocumented
394 0 $LastCmd = "CQI_CL_CPOS2RBOUND($attribute, [@_])";
395 0 cqi_send_word($CWB::CQI::CL_CPOS2RBOUND);
396 0 cqi_send_string($attribute);
397 0 cqi_send_int_list(@_);
398 0 cqi_flush();
399 0 my @list = cqi_expect_int_list();
400 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
401 0 return @list;
402 }
403 else {
404 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
405 0 return $list[0];
406 }
407 }
408  
409 sub cqi_cpos2alg {
410 0 ▶ my $attribute = shift;
Subroutine cqi_cpos2alg: not called CC=3 SCAR=24.8
Pod undocumented
411 0 $LastCmd = "CQI_CL_CPOS2ALG($attribute, [@_])";
412 0 cqi_send_word($CWB::CQI::CL_CPOS2ALG);
413 0 cqi_send_string($attribute);
414 0 cqi_send_int_list(@_);
415 0 cqi_flush();
416 0 my @list = cqi_expect_int_list();
417 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
418 0 return @list;
419 }
420 else {
421 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
422 0 return $list[0];
423 }
424 }
425  
426 sub cqi_struc2str {
427 0 ▶ my $attribute = shift;
Subroutine cqi_struc2str: not called CC=3 SCAR=24.8
Pod undocumented
428 0 $LastCmd = "CQI_CL_STRUC2STR($attribute, [@_])";
429 0 cqi_send_word($CWB::CQI::CL_STRUC2STR);
430 0 cqi_send_string($attribute);
431 0 cqi_send_int_list(@_);
432 0 cqi_flush();
433 0 my @list = cqi_expect_string_list();
434 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
435 0 return @list;
436 }
437 else {
438 0 ▶ croak "Called in scalar context with list argument." unless @list == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @list == 1 0 0 0
439 0 return $list[0];
440 }
441 }
442  
443 sub cqi_id2cpos {
444 0 ▶ croak "USAGE: \@cposlist = cqi_id2cpos(\$attribute, \$id);"
Subroutine cqi_id2cpos: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and wantarray 0 0 0
Condition0%0/3
@_ == 2 and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 2 and wantarray
@_ == 2 wantarray
Truth table0%0/3
A and B
A= @_ == 2B= wantarray
ABresult
0X0
100
111
445 unless @_ == 2 and wantarray;
446 0 my $attribute = shift;
447 0 my $id = shift;
448  
449 0 $LastCmd = "CQI_CL_ID2CPOS($attribute, $id)";
450 0 cqi_send_word($CWB::CQI::CL_ID2CPOS);
451 0 cqi_send_string($attribute);
452 0 cqi_send_int($id);
453 0 cqi_flush();
454 0 return cqi_expect_int_list();
455 }
456  
457 sub cqi_idlist2cpos {
458 0 ▶ my $attribute = shift;
Subroutine cqi_idlist2cpos: not called CC=1 SCAR=6.9
Pod undocumented
459 0 $LastCmd = "CQI_CL_IDLIST2CPOS($attribute, [@_])";
460 0 cqi_send_word($CWB::CQI::CL_IDLIST2CPOS);
461 0 cqi_send_string($attribute);
462 0 cqi_send_int_list(@_);
463 0 cqi_flush();
464 0 return cqi_expect_int_list();
465 }
466  
467 sub cqi_regex2id {
468 0 ▶ croak "USAGE: \@idlist = cqi_regex2id(\$attribute, \$regex);"
Subroutine cqi_regex2id: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and wantarray 0 0 0
Condition0%0/3
@_ == 2 and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 2 and wantarray
@_ == 2 wantarray
Truth table0%0/3
A and B
A= @_ == 2B= wantarray
ABresult
0X0
100
111
469 unless @_ == 2 and wantarray;
470 0 my $attribute = shift;
471 0 my $regex = shift;
472  
473 0 $LastCmd = "CQI_CL_REGEX2ID($attribute, $regex)";
474 0 cqi_send_word($CWB::CQI::CL_REGEX2ID);
475 0 cqi_send_string($attribute);
476 0 cqi_send_string($regex);
477 0 cqi_flush();
478 0 return cqi_expect_int_list();
479 }
480  
481 sub cqi_struc2cpos {
482 0 ▶ croak "USAGE: (\$start, \$end) = cqi_struc2cpos(\$attribute, \$struc);"
Subroutine cqi_struc2cpos: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and wantarray 0 0 0
Condition0%0/3
@_ == 2 and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 2 and wantarray
@_ == 2 wantarray
Truth table0%0/3
A and B
A= @_ == 2B= wantarray
ABresult
0X0
100
111
483 unless @_ == 2 and wantarray;
484 0 my $attribute = shift;
485 0 my $struc = shift;
486  
487 0 $LastCmd = "CQI_CL_STRUC2CPOS($attribute, $struc)";
488 0 cqi_send_word($CWB::CQI::CL_STRUC2CPOS);
489 0 cqi_send_string($attribute);
490 0 cqi_send_int($struc);
491 0 cqi_flush();
492 0 return cqi_expect_int_int();
493 }
494  
495 sub cqi_alg2cpos {
496 0 ▶ croak "USAGE: (\$s1, \$s2, \$t1, \$t2) = cqi_alg2cpos(\$attribute, \$alg);"
Subroutine cqi_alg2cpos: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and wantarray 0 0 0
Condition0%0/3
@_ == 2 and wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 2 and wantarray
@_ == 2 wantarray
Truth table0%0/3
A and B
A= @_ == 2B= wantarray
ABresult
0X0
100
111
497 unless @_ == 2 and wantarray;
498 0 my $attribute = shift;
499 0 my $alg = shift;
500  
501 0 $LastCmd = "CQI_CL_ALG2CPOS($attribute, $alg)";
502 0 cqi_send_word($CWB::CQI::CL_ALG2CPOS);
503 0 cqi_send_string($attribute);
504 0 cqi_send_int($alg);
505 0 cqi_flush();
506 0 return cqi_expect_int_int_int_int();
507 }
508  
509 # cqi_query() returns a CQi response code (CQI_STATUS_OK or error).
510 # An error code usually indicates a mistake in the query syntax.
511 # It aborts the program unless one of the following responses is received:
512 # CQI_STATUS_OK
513 # CQI_ERROR_*
514 # CQI_CQP_ERROR_*
515 sub cqi_query {
516 0 ▶ my ($mother, $child, $query) = @_;
Subroutine cqi_query: not called CC=8 SCAR=42.8
Pod undocumented
517 0 ▶ croak "USAGE: \$ok = cqi_query(\$mother_corpus, \$subcorpus_name, \$query);"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 3 and $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/ and $child =~ /^[A-Z_][A-Za-z0-9_-]*$/ 0 0 0
Condition0%0/6
@_ == 3 and $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/ and $child =~ /^[A-Z_][A-Za-z0-9_-]*$/
!ll&&!rl&&r
000
@_ == 3 and $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/
!ll&&!rl&&r
000
MC/DC0%0/3
@_ == 3 and $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/ and $child =~ /^[A-Z_][A-Za-z0-9_-]*$/
@_ == 3 $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/ $child =~ /^[A-Z_][A-Za-z0-9_-]*$/
Truth table0%0/4
A and B and C
A= @_ == 3B= $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/C= $child =~ /^[A-Z_][A-Za-z0-9_-]*$/
ABCresult
0XX0
10X0
1100
1111
518 unless @_ == 3 and $mother =~ /^[A-Z0-9_-]+(:[A-Z_][A-Za-z0-9_-]*)?$/
519 and $child =~ /^[A-Z_][A-Za-z0-9_-]*$/;
520 0 ▶ $query .= ";"
Branch: 1 branch
BranchTrueFalseTotal
unless $query =~ /;\s*$/ 0 0 0
521 unless $query =~ /;\s*$/;
522
523 0 $LastCmd = "CQI_CQP_QUERY($mother, $child, '$query')";
524 0 cqi_send_word($CWB::CQI::CQP_QUERY);
525 0 cqi_send_string($mother);
526 0 cqi_send_string($child);
527 0 cqi_send_string($query);
528 0 cqi_flush();
529 0 my $response = cqi_read_word();
530 0 my $group = $response >> 8;
531 0 ▶ CqiError $response
Branch: 1 branch
BranchTrueFalseTotal
unless $response == $CWB::CQI::STATUS_OK or $group == $CWB::CQI::ERROR or $group == $CWB::CQI::CQP_ERROR 0 0 0
Condition0%0/6
$response == $CWB::CQI::STATUS_OK or $group == $CWB::CQI::ERROR or $group == $CWB::CQI::CQP_ERROR
l!l&&r!l&&!r
000
$response == $CWB::CQI::STATUS_OK or $group == $CWB::CQI::ERROR
l!l&&r!l&&!r
000
MC/DC0%0/3
$response == $CWB::CQI::STATUS_OK or $group == $CWB::CQI::ERROR or $group == $CWB::CQI::CQP_ERROR
$response == $CWB::CQI::STATUS_OK $group == $CWB::CQI::ERROR $group == $CWB::CQI::CQP_ERROR
Truth table0%0/4
A or B or C
A= $response == $CWB::CQI::STATUS_OKB= $group == $CWB::CQI::ERRORC= $group == $CWB::CQI::CQP_ERROR
ABCresult
1XX1
01X1
0011
0000
532 unless $response == $CWB::CQI::STATUS_OK or $group == $CWB::CQI::ERROR or $group == $CWB::CQI::CQP_ERROR;
533 0 return $response;
534 }
535  
536 sub cqi_list_subcorpora {
537 0 ▶ my $corpus = shift;
Subroutine cqi_list_subcorpora: not called CC=1 SCAR=6.9
Pod undocumented
538 0 $LastCmd = "CQI_CQP_LIST_SUBCORPORA($corpus)";
539 0 cqi_send_word($CWB::CQI::CQP_LIST_SUBCORPORA);
540 0 cqi_send_string($corpus);
541 0 cqi_flush();
542 0 return cqi_expect_string_list();
543 }
544  
545 sub cqi_subcorpus_size {
546 0 ▶ my $subcorpus = shift;
Subroutine cqi_subcorpus_size: not called CC=1 SCAR=6.9
Pod undocumented
547 0 $LastCmd = "CQI_CQP_SUBCORPUS_SIZE($subcorpus)";
548 0 cqi_send_word($CWB::CQI::CQP_SUBCORPUS_SIZE);
549 0 cqi_send_string($subcorpus);
550 0 cqi_flush();
551 0 return cqi_expect_int();
552 }
553  
554 # used internally
555 sub cqi_get_field_key {
556 0 ▶ my $field = uc shift;
Subroutine cqi_get_field_key: not called CC=2 SCAR=17.9
Pod undocumented
557 0 ▶ if ($field =~ /^(MATCH(END)?|TARGET|KEYWORD)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field =~ /^(MATCH(END)?|TARGET|KEYWORD)$/) { } 0 0 0
558 0 return eval "\$CWB::CQI::CONST_FIELD_$field";
559 }
560 else {
561 0 return undef;
562 }
563 }
564  
565 sub cqi_subcorpus_has_field {
566 0 ▶ my ($subcorpus, $field) = @_;
Subroutine cqi_subcorpus_has_field: not called CC=3 SCAR=24.8
Pod undocumented
567 0 ▶ croak "USAGE: \$ok = cqi_subcorpus_has_field(\$subcorpus, 'match'|'matchend'|'target'|'keyword');"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and defined(my $field_key = cqi_get_field_key($field)) 0 0 0
Condition0%0/3
@_ == 2 and defined(my $field_key = cqi_get_field_key($field))
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 2 and defined(my $field_key = cqi_get_field_key($field))
@_ == 2 defined(my $field_key = cqi_get_field_key($field))
Truth table0%0/3
A and B
A= @_ == 2B= defined(my $field_key = cqi_get_field_key($field))
ABresult
0X0
100
111
568 unless @_ == 2 and defined (my $field_key = cqi_get_field_key($field));
569 0 $LastCmd = "CQI_CQP_SUBCORPUS_HAS_FIELD($subcorpus, CQI_CONST_FIELD_".(uc $field).")";
570 0 cqi_send_word($CWB::CQI::CQP_SUBCORPUS_HAS_FIELD);
571 0 cqi_send_string($subcorpus);
572 0 cqi_send_byte($field_key);
573 0 cqi_flush();
574 0 return cqi_expect_bool();
575 }
576  
577 sub cqi_dump_subcorpus {
578 0 ▶ my ($subcorpus, $field, $first, $last) = @_;
Subroutine cqi_dump_subcorpus: not called CC=3 SCAR=24.8
Pod undocumented
579 0 ▶ croak "USAGE: \@column = cqi_dump_subcorpus(\$subcorpus, 'match'|'matchend'|'target'|'keyword', \$from, \$to);"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 4 and defined(my $field_key = cqi_get_field_key($field)) 0 0 0
Condition0%0/3
@_ == 4 and defined(my $field_key = cqi_get_field_key($field))
!ll&&!rl&&r
000
MC/DC0%0/2
@_ == 4 and defined(my $field_key = cqi_get_field_key($field))
@_ == 4 defined(my $field_key = cqi_get_field_key($field))
Truth table0%0/3
A and B
A= @_ == 4B= defined(my $field_key = cqi_get_field_key($field))
ABresult
0X0
100
111
580 unless @_ == 4 and defined (my $field_key = cqi_get_field_key($field));
581 0 $LastCmd = "CQI_CQP_DUMP_SUBCORPUS($subcorpus, CQI_CONST_FIELD_".(uc $field).", $first, $last)";
582 0 cqi_send_word($CWB::CQI::CQP_DUMP_SUBCORPUS);
583 0 cqi_send_string($subcorpus);
584 0 cqi_send_byte($field_key);
585 0 cqi_send_int($first);
586 0 cqi_send_int($last);
587 0 cqi_flush();
588 0 return cqi_expect_int_list();
589 }
590  
591 sub cqi_drop_subcorpus {
592 0 ▶ my $subcorpus = shift;
Subroutine cqi_drop_subcorpus: not called CC=1 SCAR=6.9
Pod undocumented
593 0 $LastCmd = "CQI_CQP_DROP_SUBCORPUS($subcorpus)";
594 0 cqi_send_word($CWB::CQI::CQP_DROP_SUBCORPUS);
595 0 cqi_send_string($subcorpus);
596 0 cqi_flush();
597 0 cqi_expect_status($CWB::CQI::STATUS_OK);
598 }
599  
600 ## cqi_fdist() subsumes both cqi_fdist_1() and cqi_fdist_2()
601 ## returns list of (id, f) or (id1, id2, f) tuples as hashref's
602 sub cqi_fdist {
603 0 ▶ my $subcorpus = shift;
Subroutine cqi_fdist: not called CC=11 SCAR=48.8
Pod undocumented
604 0 my $cutoff = shift;
605 0 my $key1 = shift;
606 0 my $key2 = shift;
607 0 my ($field1, $field2, $att1, $att2, $tmp);
608 0 ($tmp, $att1) = split /\./, $key1;
609 0 $field1 = cqi_get_field_key($tmp);
610 0 ▶ if (defined $key2) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key2) { } 0 0 0
611 0 ($tmp, $att2) = split /\./, $key2;
612 0 $field2 = cqi_get_field_key($tmp);
613 }
614 else {
615 0 $field2 = "";
616 0 $att2 = "x";
617 }
618 0 ▶ croak "USAGE: \@table = cqi_fdist(\$subcorpus, \$cutoff, \$key1 [, \$key2]);"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2 and $att1 =~ /^[a-z]+$/ and $att2 =~ /^[a-z]+$/ and $cutoff >= 0 0 0 0
Condition0%0/21
@_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2 and $att1 =~ /^[a-z]+$/ and $att2 =~ /^[a-z]+$/ and $cutoff >= 0
!ll&&!rl&&r
000
@_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2 and $att1 =~ /^[a-z]+$/ and $att2 =~ /^[a-z]+$/
!ll&&!rl&&r
000
@_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2 and $att1 =~ /^[a-z]+$/
!ll&&!rl&&r
000
@_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2
!ll&&!rl&&r
000
@_ == 0 and defined $field1 and defined $field2 and defined $att1
!ll&&!rl&&r
000
@_ == 0 and defined $field1 and defined $field2
!ll&&!rl&&r
000
@_ == 0 and defined $field1
!ll&&!rl&&r
000
MC/DC0%0/8
@_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2 and $att1 =~ /^[a-z]+$/ and $att2 =~ /^[a-z]+$/ and $cutoff >= 0
@_ == 0 defined $field1 defined $field2 defined $att1 defined $att2 $att1 =~ /^[a-z]+$/ $att2 =~ /^[a-z]+$/ $cutoff >= 0
Truth table0%0/9
A and B and C and D and E and F and G and H
A= @_ == 0B= defined $field1C= defined $field2D= defined $att1E= defined $att2F= $att1 =~ /^[a-z]+$/G= $att2 =~ /^[a-z]+$/H= $cutoff >= 0
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
619 unless @_ == 0 and defined $field1 and defined $field2 and defined $att1 and defined $att2
620 and $att1 =~ /^[a-z]+$/ and $att2 =~ /^[a-z]+$/ and $cutoff >= 0;
621 0 ▶ if ($field2 ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($field2 ne '') { } 0 0 0
622 0 $LastCmd = "CQI_CQP_FDIST_2($subcorpus, $cutoff, $key1, $key2)";
623 0 cqi_send_word($CWB::CQI::CQP_FDIST_2);
624 0 cqi_send_string($subcorpus);
625 0 cqi_send_int($cutoff);
626 0 cqi_send_byte($field1);
627 0 cqi_send_string($att1);
628 0 cqi_send_byte($field2);
629 0 cqi_send_string($att2);
630 0 cqi_flush();
631 0 return cqi_expect_int_table();
632 }
633 else {
634 0 $LastCmd = "CQI_CQP_FDIST_1($subcorpus, $cutoff, $key1)";
635 0 cqi_send_word($CWB::CQI::CQP_FDIST_1);
636 0 cqi_send_string($subcorpus);
637 0 cqi_send_int($cutoff);
638 0 cqi_send_byte($field1);
639 0 cqi_send_string($att1);
640 0 cqi_flush();
641 0 return cqi_expect_int_table();
642 }
643 }
644  
645  
646 #
647 #
648 # CQi expect response / data
649 #
650 #
651 sub cqi_expect_byte {
652 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_byte: not called CC=1 SCAR=6.9
Pod undocumented
653 0 CqiCheckResponse $r, $CWB::CQI::DATA_BYTE;
654 0 return cqi_read_byte();
655 }
656  
657 sub cqi_expect_bool {
658 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_bool: not called CC=1 SCAR=6.9
Pod undocumented
659 0 CqiCheckResponse $r, $CWB::CQI::DATA_BOOL;
660 0 return cqi_read_byte();
661 }
662  
663 sub cqi_expect_int {
664 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_int: not called CC=1 SCAR=6.9
Pod undocumented
665 0 CqiCheckResponse $r, $CWB::CQI::DATA_INT;
666 0 return cqi_read_int();
667 }
668  
669 sub cqi_expect_string {
670 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_string: not called CC=1 SCAR=6.9
Pod undocumented
671 0 CqiCheckResponse $r, $CWB::CQI::DATA_STRING;
672 0 return cqi_read_string();
673 }
674  
675 sub cqi_expect_byte_list {
676 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_byte_list: not called CC=1 SCAR=6.9
Pod undocumented
677 0 CqiCheckResponse $r, $CWB::CQI::DATA_BYTE_LIST;
678 0 return cqi_read_byte_list();
679 }
680  
681 sub cqi_expect_bool_list {
682 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_bool_list: not called CC=1 SCAR=6.9
Pod undocumented
683 0 CqiCheckResponse $r, $CWB::CQI::DATA_BOOL_LIST;
684 0 return cqi_read_byte_list();
685 }
686  
687 sub cqi_expect_int_list {
688 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_int_list: not called CC=1 SCAR=6.9
Pod undocumented
689 0 CqiCheckResponse $r, $CWB::CQI::DATA_INT_LIST;
690 0 return cqi_read_int_list();
691 }
692  
693 sub cqi_expect_string_list {
694 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_string_list: not called CC=1 SCAR=6.9
Pod undocumented
695 0 CqiCheckResponse $r, $CWB::CQI::DATA_STRING_LIST;
696 0 return cqi_read_string_list();
697 }
698  
699 sub cqi_expect_int_int {
700 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_int_int: not called CC=1 SCAR=6.9
Pod undocumented
701 0 CqiCheckResponse $r, $CWB::CQI::DATA_INT_INT;
702 0 return cqi_read_int(), cqi_read_int();
703 }
704  
705 sub cqi_expect_int_int_int_int {
706 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_int_int_int_int: not called CC=1 SCAR=6.9
Pod undocumented
707 0 CqiCheckResponse $r, $CWB::CQI::DATA_INT_INT_INT_INT;
708 0 return cqi_read_int(), cqi_read_int(), cqi_read_int(), cqi_read_int();
709 }
710  
711 sub cqi_expect_int_table {
712 0 ▶ my $r = cqi_read_word();
Subroutine cqi_expect_int_table: not called CC=1 SCAR=6.9
Pod undocumented
713 0 CqiCheckResponse $r, $CWB::CQI::DATA_INT_TABLE;
714 0 return cqi_read_int_table();
715 }
716  
717 sub cqi_expect_status {
718 0 ▶ my @expected = @_; # arguments are list of acceptable responses
Subroutine cqi_expect_status: not called CC=1 SCAR=6.9
Pod undocumented
719 0 my $r = cqi_read_word();
720 0 CqiCheckResponse $r, @expected;
721 0 return $r;
722 }
723  
724  
725 #
726 #
727 # Internal subroutines (read / write)
728 #
729 #
730 sub cqi_send_byte ($) {
731 0 ▶ $conn->print((pack "C", shift))
Subroutine cqi_send_byte: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$conn->print(pack("C", shift())) or croak("cqi_send_byte(): $!") 0 0 0
732 or croak "cqi_send_byte(): $!";
733 }
734  
735 sub cqi_send_word ($) {
736 0 ▶ $conn->print((pack "n", shift))
Subroutine cqi_send_word: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$conn->print(pack("n", shift())) or croak("cqi_send_word(): $!") 0 0 0
737 or croak "cqi_send_word(): $!";
738 }
739  
740 sub cqi_send_int ($) {
741 0 ▶ my $number = shift; # safely convert native int to 32bit value
Subroutine cqi_send_int: not called CC=2 SCAR=17.9
Pod undocumented
742 0 $number = unpack "L", (pack "l", $number); # pack 32bit signed, unpack unsigned -> uses type which can hold unsigned 32bit value
743 0 ▶ $conn->print(pack("N", $number)) # 'N' packs unsigned 32bit integer
Branch: 1 branch
BranchTrueFalseTotal
$conn->print(pack("N", $number)) or croak("cqi_send_int(): $!") 0 0 0
744 or croak "cqi_send_int(): $!";
745 }
746  
747 sub cqi_send_string ($) {
748 0 ▶ my $str = shift;
Subroutine cqi_send_string: not called CC=2 SCAR=17.9
Pod undocumented
749 0 ▶ $conn->print((pack "n", length $str), $str)
Branch: 1 branch
BranchTrueFalseTotal
$conn->print(pack("n", length $str), $str) or croak("cqi_send_str(): $!") 0 0 0
750 or croak "cqi_send_str(): $!";
751 }
752  
753 sub cqi_send_byte_list (@) {
754 0 ▶ cqi_send_int(scalar @_);
Subroutine cqi_send_byte_list: not called CC=1 SCAR=6.9
Pod undocumented
755 0 map {cqi_send_byte($_)} @_;
756 }
757  
758 sub cqi_send_word_list (@) {
759 0 ▶ cqi_send_int(scalar @_);
Subroutine cqi_send_word_list: not called CC=1 SCAR=6.9
Pod undocumented
760 0 map {cqi_send_word($_)} @_;
761 }
762  
763 sub cqi_send_int_list (@) {
764 0 ▶ cqi_send_int(scalar @_);
Subroutine cqi_send_int_list: not called CC=1 SCAR=6.9
Pod undocumented
765 0 map {cqi_send_int($_)} @_;
766 }
767  
768 sub cqi_send_string_list (@) {
769 0 ▶ cqi_send_int(scalar @_);
Subroutine cqi_send_string_list: not called CC=1 SCAR=6.9
Pod undocumented
770 0 map {cqi_send_string($_)} @_;
771 }
772  
773 sub cqi_flush () {
774 0 ▶ $conn->flush
Subroutine cqi_flush: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$conn->flush or croak("cqi_flush(): $!") 0 0 0
775 or croak "cqi_flush(): $!";
776 }
777  
778 sub cqi_read_byte () {
779 0 ▶ my $msg = $conn->getc();
Subroutine cqi_read_byte: not called CC=2 SCAR=17.9
Pod undocumented
780 0 ▶ croak "cqi_read_byte(): $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $msg 0 0 0
781 unless defined $msg;
782 0 return unpack "C", $msg;
783 }
784  
785 sub cqi_read_word () {
786 0 ▶ my $msg;
Subroutine cqi_read_word: not called CC=3 SCAR=24.8
Pod undocumented
787 0 my $bytes_read = $conn->read($msg, 2);
788 0 ▶ croak "cqi_read_word(): $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_read and $bytes_read == 2 0 0 0
Condition0%0/3
defined $bytes_read and $bytes_read == 2
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bytes_read and $bytes_read == 2
defined $bytes_read $bytes_read == 2
Truth table0%0/3
A and B
A= defined $bytes_readB= $bytes_read == 2
ABresult
0X0
100
111
789 unless defined $bytes_read and $bytes_read == 2;
790 0 return unpack "N", "\x00\x00$msg"; # this should safely unpack an unsigned short
791 }
792  
793 sub cqi_read_int () {
794 0 ▶ my $msg;
Subroutine cqi_read_int: not called CC=3 SCAR=24.8
Pod undocumented
795 my $number;
796
797 0 my $bytes_read = $conn->read($msg, 4);
798 0 ▶ croak "cqi_read_word(): $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_read and $bytes_read == 4 0 0 0
Condition0%0/3
defined $bytes_read and $bytes_read == 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bytes_read and $bytes_read == 4
defined $bytes_read $bytes_read == 4
Truth table0%0/3
A and B
A= defined $bytes_readB= $bytes_read == 4
ABresult
0X0
100
111
799 unless defined $bytes_read and $bytes_read == 4;
800 0 $number = unpack "N", $msg; # unpack seems to default to unsigned
801 0 $number = unpack "l", (pack "L", $number); # convert unsigned 32bit to internal signed int *phew*
802 0 return $number;
803 }
804  
805 sub cqi_read_string () {
806 0 ▶ my ($msg, $len, $bytes_read);
Subroutine cqi_read_string: not called CC=3 SCAR=24.8
Pod undocumented
807 0 $len = cqi_read_word();
808 0 $bytes_read = $conn->read($msg, $len);
809 0 ▶ croak "cqi_read_string(): $!"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $bytes_read and $bytes_read == $len 0 0 0
Condition0%0/3
defined $bytes_read and $bytes_read == $len
!ll&&!rl&&r
000
MC/DC0%0/2
defined $bytes_read and $bytes_read == $len
defined $bytes_read $bytes_read == $len
Truth table0%0/3
A and B
A= defined $bytes_readB= $bytes_read == $len
ABresult
0X0
100
111
810 unless defined $bytes_read and $bytes_read == $len;
811 0 return $msg;
812 }
813  
814 sub cqi_read_byte_list() {
815 0 ▶ my ($i, $len, @list);
Subroutine cqi_read_byte_list: not called CC=2 SCAR=17.9
Pod undocumented
816 0 $len = cqi_read_int();
817 0 ▶ for ($i = $len; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
818 0 push @list, cqi_read_byte;
819 }
820 0 return @list;
821 }
822  
823 sub cqi_read_word_list() {
824 0 ▶ my ($i, $len, @list);
Subroutine cqi_read_word_list: not called CC=2 SCAR=17.9
Pod undocumented
825 0 $len = cqi_read_int();
826 0 ▶ for ($i = $len; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
827 0 push @list, cqi_read_word();
828 }
829 0 return @list;
830 }
831  
832 sub cqi_read_int_list() {
833 0 ▶ my ($i, $len, @list);
Subroutine cqi_read_int_list: not called CC=2 SCAR=17.9
Pod undocumented
834 0 $len = cqi_read_int();
835 0 ▶ for ($i = $len; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
836 0 push @list, cqi_read_int();
837 }
838 0 return @list;
839 }
840  
841 sub cqi_read_string_list() {
842 0 ▶ my ($i, $len, @list);
Subroutine cqi_read_string_list: not called CC=2 SCAR=17.9
Pod undocumented
843 0 $len = cqi_read_int();
844 0 ▶ for ($i = $len; $i > 0; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i > 0) 0 0 0
845 0 push @list, cqi_read_string();
846 }
847 0 return @list;
848 }
849  
850 sub cqi_read_int_table() {
851 0 ▶ my $rows = cqi_read_int();
Subroutine cqi_read_int_table: not called CC=3 SCAR=24.8
Pod undocumented
852 0 my $columns = cqi_read_int();
853 0 my @table = ();
854 0 ▶ for (my $i = 0; $i < $rows; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $rows) 0 0 0
855 0 my @line = ();
856 0 ▶ for (my $j = 0; $j < $columns; $j++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $columns) 0 0 0
857 0 push @line, cqi_read_int();
858 }
859 0 push @table, [@line];
860 }
861 0 return @table;
862 }
863  
864  
865 2 1;
866  
867 __END__
↑ Summary CQI/Client.pm »