blib/lib/Net/WoRMS.pm

filter: Statementstmt 91.1% 165 / 181 Branchbran 65.0% 65 / 100 Conditioncond 42.3% 11 / 26 MC/DCmcdc 5.8% 1 / 17 Subroutinesub 96.8% 31 / 32 Podpod 100% 17 / 17 totaltotal 77.7% 290 / 373 CC 64 SCAR 31.2
CC
64
Cov
79%
printRecord
54.2
searchSpeciesID
19.0
printRecordDef
18.0
CRAP 22.6
↑ Summary
1 package Net::WoRMS;
2 # ======================================================================
3 # (C) 2012 by A. Weidauer
4 # Contact: alex.weidauer@huckfinn.de
5 # ======================================================================
6 # ABSTRACT: Service object to query the "World Register of Marine Species" WoRMS.
7 # ======================================================================
8 =head1 NAME
9  
10 Net::WoRMS provides functions to query the "World Register of Marine Species".
11  
12 =head1 VERSION
13  
14 version 1.8
15  
16 =head1 SYNOPSIS
17  
18 Net::WoRMS bundles WEB access, parsing and formatting capabilities for
19 the tool L<query-worms|https://metacpan.org>, to harvest information
20 form the "World Register of Marine Species" --
21 L<http://www.marinespecies.org>. The module was built around the module
22 L<SOAP::Lite> and is OO implemented using L<Moo>.
23  
24 =cut
25  
26 # ======================================================================
27 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 3 ▶use open qw(:std :utf8);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 3 our $VERSION = 1.7;
34  
35 # ----------------------------------------------------------------------
36  
37 =head1 DEPENDENCIES
38  
39 The module uses the packages:
40  
41 =over
42  
43 =item L<Data::Dumper>
44  
45 Debugging purposes
46  
47 =item L<Moo>
48  
49 Object oriented extension for the module
50  
51 =item L<MooX::Types::MooseLike::Base>
52  
53 Minimal type system for L<Moo>
54  
55 =item L<SOAP::Lite>
56  
57 is used for the WEB access and parsing capabilities to retrieve data
58 from L<http://www.marinespecies.org>.
59  
60 =item L<Syntax::Keyword::Match>
61  
62 to end the switch-case/while-given madness
63  
64 =back
65  
66 =cut
67  
68 # Modules -------------------------------------------------------------
69 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 3 ▶use MooX::Types::MooseLike::Base qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
71 3 ▶use SOAP::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 # Modern Perl ----------------------------------------------------------
75 3 ▶use Syntax::Keyword::Match;
Subroutine BEGIN: called CC=1 SCAR=0.0
76 3 ▶use feature qw(signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
77 3 ▶no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
78 3 ▶no warnings 'experimental';
Subroutine BEGIN: called CC=1 SCAR=0.0
79 3 ▶no warnings 'experimental::signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 # ---------------------------------------------------------------------
82  
83 =head1 VARIABLES and CONSTANTS
84  
85 =over
86  
87 =item $END_POINT = 'http://www.marinespecies.org/aphia.php?p=soap'
88  
89 The access point to retrieve data via the Simple Object Access Protocol.
90  
91 =item $APHIA_NS = 'http://aphia/v1.0'
92  
93 Namespace and corresponding URI. In the development context these
94 variables are considered as a constants. There are methods to change
95 these values but never tested.
96  
97 =item $FORMAT = 'TEXT'
98  
99 FORMAT defines the default output format.
100  
101 =item @ORDER_SCORE = qw/APHIA_ID ... /
102  
103 The array holds field names for SQL related output.
104  
105 =item @ORDER_DOT = qw/APHIA.ID ... /
106  
107 The array holds field names for TEXT and CSV related output.
108  
109 =item %FORMATS = ( TEXT => 1, SQL => 2, CSV => 3)
110  
111 The format hash mostly for validation.
112  
113 =item %ORDER_HASH
114  
115 Dictionary to sort and translate the retrieved field names from the
116 WoRMS database and bring them into a consistent form.
117  
118 =item @TYPE
119  
120 Type array corresponding to C<@ORDER_SCORE/@ORDER_DOT> and the
121 C<%ORDER_HASH> to handle quotes and C<NULL> values.
122  
123 =back
124  
125 =cut
126  
127 # GLOBALS ==============================================================
128 3 my $END_POINT = 'http://www.marinespecies.org/aphia.php?p=soap';
129 3 my $APHIA_NS = 'http://aphia/v1.0';
130 3 my $APHIA_URI = $APHIA_NS;
131 3 my $FORMAT = 'TEXT';
132  
133 # Field name dump output
134 3 my @ORDER_SCORE =
135 qw/APHIA_ID NAME AUTHOR RANK STATUS VALID_APHIA_ID VALID_NAME
136 VALID_AUTHOR RNK_KINGDOM RNK_PHYLUM RNK_CLASS RNK_ORDER
137 RNK_FAMILY RNK_GENUS CITATION/;
138  
139 # Field names SQL / CSV
140 3 my @ORDER_DOT = qw/APHIA.ID NAME AUTHOR RANK STATUS VALID.APHIA.ID VALID.NAME
141 VALID.AUTHOR KINGDOM PHYLUM CLASS ORDER
142 FAMILY GENUS CITATION/;
143  
144 3 my %FORMATS = ( TEXT => 1, SQL => 2, CSV => 3);
145  
146 # SOAP entry mapping to field names - WoRMS keys are a mess
147 3 my %ORDER_HASH = (
148 "AphiaID" => 0, "scientificname" => 1, "authority" => 2,
149 "rank" => 3, "status" => 4,
150 "valid_AphiaID" => 5, "valid_name" => 6, "valid_authority" => 7,
151 "kingdom" => 8, "phylum" => 9, "class" => 10,
152 "order" => 11, "family" => 12, "genus" => 13,
153 "citation" => 14,);
154  
155 # Data types of the fields
156 # Index 0 1 2 3 4 5 6 7 8 9
157 3 my @TYPE = qw (INT STR STR STR STR INT STR STR STR STR
158 STR STR STR STR STR);
159  
160 # ----------------------------------------------------------------------
161  
162 =head1 FIELDS
163  
164 =over
165  
166 =item Debug: BOOL
167  
168 Flag to switch to the debugging mode.
169  
170 =item Format: STR
171  
172 Field holds the current output format. The tags "TEXT|SQL|CSV" are
173 allowed.
174  
175 =item EndPoint: STR (URI)
176  
177 The current SOAP endpoint defaults to C<$END_POINT>.
178  
179 =item AphiaNS and AphiaURI: STR (URI)
180  
181 The current namespace and corresponding URI, defaulting to $APHIA_NS.
182  
183 =item Soap
184  
185 The SOAP access client instance generate by L<SOAP::Lite>.
186  
187 =back
188  
189 =cut
190  
191 # FIELDS ===============================================================
192 3 has Debug => ( is => 'rwp', isa => Int, default => 0 );
193 3 has Format => ( is => 'rwp', isa => Str, default => $FORMAT );
194 3 has EndPoint => ( is => 'rwp', isa => Str, default => $END_POINT );
195 3 has AphiaNS => ( is => 'rwp', isa => Str, default => $APHIA_NS );
196 3 has AphiaURI => ( is => 'rwp', isa => Str, default => $APHIA_URI );
197 3 has Soap => (
198 is => 'rwp',
199 );
200  
201 # METHODS ==============================================================
202  
203 =head1 METHODS
204  
205 =over
206  
207 =item init()
208  
209 Initializes the SOAP client.
210  
211 Note: All C<change*(...)> functions must be used before the
212 initialization phase.
213  
214 =item _checkInit($what)
215  
216 Internal initialization test to assert the task C<$what> was not
217 recycled.
218  
219 =back
220  
221 =cut
222  
223 1 ▶sub init($self) {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
224 1 $self->_set_Soap( SOAP::Lite->new(
225 uri => $self->AphiaURI,
226 proxy => $self->EndPoint));
227 }
228  
229 4 ▶sub _checkInit($self, $what) {
Subroutine _checkInit: called CC=2 SCAR=7.6
230 4 ▶ die "You have to change the '$what' before the ".
Branch: 1 branch
BranchTrueFalseTotal
if $self->Soap 0 4 4
231 "initialization of the connection!" if $self->Soap;
232 }
233  
234 # ----------------------------------------------------------------------
235  
236 =head2 CONFIGURATION
237  
238 =over
239  
240 =item changeEndPoint($uri)
241  
242 Change the end point for the soap client (don't change).
243  
244 =item changeAphiaURI($uri)
245  
246 Change the namespace URI for the soap client (don't change).
247  
248 =item changeAphiaNS($uri)
249  
250 Change the namespace soap soap client (don't change).
251  
252 =item changeDebug($flag)
253  
254 Demand debugging capabilities.
255  
256 =item changeFormat($format)
257  
258 Changes the output format. Valid formats are TEXT|CSV|SQL.
259  
260 =item getFormats()
261  
262 Get the format dictionary for validation.
263  
264 =back
265  
266 =cut
267  
268 # Function to configure the net access --------------------------------
269  
270 1 ▶sub changeEndPoint($self, $endPoint) {
Subroutine changeEndPoint: called CC=1 SCAR=0.0
Pod documented
271 1 $self->_checkInit('END.POINT');
272 1 $self->_set_EndPoint($endPoint);
273 }
274  
275 1 ▶sub changeAphiaURI($self, $aphiaUri) {
Subroutine changeAphiaURI: called CC=1 SCAR=0.0
Pod documented
276 1 $self->_checkInit('APHIA.URI');
277 1 $self->_set_AphiaURI($aphiaUri);
278 }
279  
280 1 ▶sub changeAphiaNS($self, $aphiaNS) {
Subroutine changeAphiaNS: called CC=1 SCAR=0.0
Pod documented
281 1 $self->_checkInit('APHIA.NS');
282 1 $self->_set_AphiaNS($aphiaNS);
283 }
284  
285 1 ▶sub changeDebug($self, $debug) {
Subroutine changeDebug: called CC=1 SCAR=0.0
Pod documented
286 1 $self->_checkInit('DEBUG');
287 1 $self->_set_Debug($debug);
288 }
289  
290 3 ▶sub changeFormat($self, $format) {
Subroutine changeFormat: called CC=1 SCAR=0.0
Pod documented
291 # $self->_checkInit('FORMAT');
292 3 $self->_set_Format($format);
293 }
294  
295 3 ▶sub getFormats($self) { return \%FORMATS; }
Subroutine getFormats: called CC=1 SCAR=0.0
Pod documented
296  
297 # ----------------------------------------------------------------------
298  
299 =head2 ASSERTATIONS
300  
301 =over
302  
303 =item checkSoap()
304  
305 Check if the soap client is running. The function stops the calling
306 program C<(die ...)> in case of an error.
307  
308 =item checkError($soapResponse)
309  
310 Checks the SOAP query result. The function stops the calling program in
311 case of an communication error.
312  
313 =item checkDebug($queryResult)
314  
315 Prints the query result (dictionary) via L<Data::Dumper> to C<STDERR> if
316 the debug flag is set.
317  
318 =back
319  
320 =cut
321  
322 7 ▶sub checkSoap($self) {
Subroutine checkSoap: called CC=2 SCAR=7.1
Pod documented
323 7 my $res = $self->Soap;
324 7 ▶ die "Missing connection!" if not $res;
Branch: 1 branch
BranchTrueFalseTotal
unless $res 0 7 7
325 7 return $res;
326 }
327  
328 6 ▶sub checkError($self, $response) {
Subroutine checkError: called CC=2 SCAR=7.6
Pod documented
329 6 ▶ die "ERROR: ".$response->faultstring."!\n" if $response->fault;
Branch: 1 branch
BranchTrueFalseTotal
if $response->fault 0 6 6
330 }
331  
332 4 ▶sub checkDebug($self, $result) {
Subroutine checkDebug: called CC=2 SCAR=7.6
Pod documented
333 4 ▶ print STDERR "DGB BEGIN:\n",Dumper($result),"EOF\n" if $self->Debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Debug 0 4 4
334 }
335  
336 # ----------------------------------------------------------------
337  
338 =head2 QUERIES
339  
340 =over
341  
342 =item searchSpeciesID($name, $print)
343  
344 Function to find a species by a certain name. The if the flag C<$print>
345 is set. The result will be written to C<STDOUT> on the given format.
346  
347 =item getRecordByID($aphiaID)
348  
349 Retrieves a record for a given AphiaID and returns a dictionary or
350 'dies' with an error.
351  
352 =item getBlockChildrenByID($AphiaID, $offs)
353  
354 Retrieve a set of taxon records under an given AphiaID for a defined
355 offset in the query ensemble. The offset addresses a paging pattern.
356  
357 =item getChildrenByID($aphiaID)
358  
359 Retrieves all children under a given AphiaID using the method
360 C<getBlockChildrenID(...)> and prints the result to C<STDOUT> using the
361 method C<printRecord(...)>.
362  
363 =item searchFuzzy($name, $offs, $fuzzy) EXPERIMENTAL
364  
365 The fuzzy search function is experimantal and does not give
366 proper results due to offset maping issues.
367  
368 =back
369  
370 =cut
371  
372 # Query functions ------------------------------------------------------
373  
374  
375 # Request to WORMS for a specific taxon by name ------------------------
376 2 ▶sub searchSpeciesID($self, $name, $print) {
Subroutine searchSpeciesID: called CC=7 SCAR=29.4
Pod documented
377 2 my $con = $self->checkSoap;
378 2 my $response = $con->call(
379 SOAP::Data->name("getAphiaID")->attr({ "xmlns" => $APHIA_NS})
380 => SOAP::Data->name("ScientificName" => $name)) ;
381 2 $self->checkError($response);
382 2 my $aphia_id = $response->result;
383 2 ▶ die "ERROR: Unknown species with the NAME: '$name'!" if not $aphia_id;
Branch: 1 branch
BranchTrueFalseTotal
unless $aphia_id 0 2 2
384 2 ▶ if ($print) {
Branch: 1 branch
BranchTrueFalseTotal
if ($print) 0 2 2
385 match($self->Format: eq) {
386 case('TEXT') {
387 0 ▶ print "INT APHIA.ID ", $aphia_id, "\n";
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 'SQL' ? : 0 0 0
388 }
389 case('SQL') {
390 0 ▶ print "APHIA_ID = ", $aphia_id, "\n"
Condition0%0/3
$(Syntax::Keyword::Match/topic) eq "CSV" and do { print $aphia_id, "\n" if $aphia_id }
!ll&&!rl&&r
000
MC/DC0%0/2
$(Syntax::Keyword::Match/topic) eq "CSV" and do { print $aphia_id, "\n" if $aphia_id }
$(Syntax::Keyword::Match/topic) eq "CSV" do { print $aphia_id, "\n" if $aphia_id }
Truth table0%0/3
A and B
A= $(Syntax::Keyword::Match/topic) eq "CSV"B= do { print $aphia_id, "\n" if $aphia_id }
ABresult
0X0
100
111
391 }
392 0 ▶ case ('CSV') {
Branch: 1 branch
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 'TEXT' ? : 0 0 0
393 0 ▶ print $aphia_id, "\n" if $aphia_id;
Branch: 1 branch
BranchTrueFalseTotal
if $aphia_id 0 0 0
394 }
395 }
396 }
397 2 return $aphia_id;
398 }
399  
400 # Request to WORMS for a specific taxon by AphiaID ---------------------
401 1 ▶sub getRecordByID($self, $id) {
Subroutine getRecordByID: called CC=1 SCAR=0.0
Pod documented
402 1 my $con = $self->checkSoap;
403 1 my $response = $con->call(
404 SOAP::Data->name("getAphiaRecordByID")->attr({ "xmlns" => $APHIA_NS})
405 => SOAP::Data->name("AphiaID") -> value($id)) ;
406 1 $self->checkError($response);
407 1 my $result = $response->result;
408 1 $self->checkDebug($result);
409 1 return $result;
410 }
411  
412 # @TODO THIS REQUEST DONT WORK -----------------------------------------
413 3 ▶sub getBlockChildrenByID($self, $id, $offs) {
Subroutine getBlockChildrenByID: called CC=1 SCAR=0.0
Pod documented
414 3 my $con = $self->checkSoap;
415 3 my $response = $con->call(
416 SOAP::Data->name("getAphiaChildrenByID")->attr({ 'xmlns' => $APHIA_NS})
417 => SOAP::Data->name("AphiaID") -> value($id),
418 => SOAP::Data->name("offset") -> value($offs),
419 => SOAP::Data->name("marine_only") -> value("false")
420 ) ;
421 3 $self->checkError($response);
422 3 my $result = $response->result;
423 3 $self->checkDebug($result);
424 3 return $result;
425 }
426  
427 # DONT WORK ------------------------------------------------------------
428 0 ▶sub searchFuzzy($self, $name, $offs, $fuzzy) {
Subroutine searchFuzzy: not called CC=1 SCAR=6.9
Pod documented
429 0 my $con = $self->checkSoap;
430 # print $name, $offs, $FUZZY, "\n";
431 0 my $response = $con->call(
432 SOAP::Data->name("getAphiaRecords")->attr({ 'xmlns' => $APHIA_NS})
433 => SOAP::Data->name("scientificname") -> value($name),
434 => SOAP::Data->name("offset") -> value($offs),
435 => SOAP::Data->name("marine_only") -> value("false"),
436 => SOAP::Data->name("like") -> value($fuzzy));
437 0 $self->checkError($response);
438 0 my $result = $response->result;
439 0 $self->checkDebug($result);
440 0 return $result;
441 }
442  
443 # ======================================================================
444  
445 1 ▶sub getChildrenByID($self, $sid) {
Subroutine getChildrenByID: called CC=10 SCAR=26.0
Pod documented
446 1 my $offs=0; my $total = 0; my $num=1;
447 1 ▶ print "\nWORMS.CHILDREN ID $sid \n" if $FORMAT eq "TEXT";
Branch: 1 branch
BranchTrueFalseTotal
if $FORMAT eq "TEXT" 1 0 1
448 1 ▶ while ($num > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 0) 3 0 3
449 3 my $found = $self->getBlockChildrenByID($sid, $offs);
450 3 ▶ last if not $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 2 3
451 2 my @recs = @$found;
452 2 ▶ if (@recs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@recs) { } 2 0 2
453 2 $num = @recs;
454 2 foreach my $rec (@recs) {
455 74 $total++;
456 74 $self->printRecord($rec, $total==1, 1," ");
457 }
458 2 $offs +=$num+1;
459 0 } else { $num=0; }
460 # print "---- $num $offs $total -----\n";
461 }
462 match($self->Format: eq) {
463 1 ▶ case('TEXT') { print "EOF\n" }
Condition0%0/3
$(Syntax::Keyword::Match/topic) eq "SQL" and do { print ";\n" if $total > 0 }
!ll&&!rl&&r
000
MC/DC0%0/2
$(Syntax::Keyword::Match/topic) eq "SQL" and do { print ";\n" if $total > 0 }
$(Syntax::Keyword::Match/topic) eq "SQL" do { print ";\n" if $total > 0 }
Truth table0%0/3
A and B
A= $(Syntax::Keyword::Match/topic) eq "SQL"B= do { print ";\n" if $total > 0 }
ABresult
0X0
100
111
464 0 ▶ case('SQL' ) { print ";\n" if $total >0; }
Branch: 1 branch
BranchTrueFalseTotal
if $total > 0 0 0 0
465 }
466 1 ▶ print "\n# WORMS.CHILDREN ID $sid TOTAL: $total\n"
Branch: 2 branches
BranchTrueFalseTotal
$(Syntax::Keyword::Match/topic) eq 'TEXT' ? : 1 0 1
if $FORMAT eq "TEXT" 1 0 1
467 if $FORMAT eq "TEXT";
468 1 $total;
469 }
470  
471 # Output service routine record DUMP, CSV and SQL ----------------------
472  
473 =head2 OUTPUT
474  
475 =over
476  
477 =item printRecord($record, $first, $last, $spc)
478  
479 Prints a record to C<STDOUT> and handles indentation by C<$spc> as well
480 as header and trailing aspects by using the flags C<$first> and C<$last>.
481  
482 =item printRecordDef($record, $record, $spc)
483  
484 Prints the default plain TEXT record to C<STDOUT> and handles
485 indentation by C<$spc>.
486  
487 =back
488  
489 =cut
490  
491 # @TODO this is a mess rewrite
492 74 ▶sub printRecord($self, $record, $first, $last, $spc) {
Subroutine printRecord: called CC=28 SCAR=39.9
Pod documented
493 # asign header section
494 74 ▶ my @head = ($self->Format eq 'TEXT')
Branch: 1 branch
BranchTrueFalseTotal
$self->Format eq 'TEXT' ? : 74 0 74
495 ? @ORDER_DOT : @ORDER_SCORE;
496  
497 74 my $num_fields = $#head;
498 74 my @data = (); my @quote = ();
499 # NULL and quotation
500 74 for my $i (0..$num_fields) {
501 # Handle empty fields
502 1110 ▶ $data[$i] = ( $self->Format eq 'SQL') ? 'NULL' : 'NA';
Branch: 1 branch
BranchTrueFalseTotal
$self->Format eq 'SQL' ? : 0 1110 1110
503 1110 ▶ $quote[$i] = ( $TYPE[$i] eq 'STR' ) ? "'" : '';
Branch: 1 branch
BranchTrueFalseTotal
$TYPE[$i] eq 'STR' ? : 962 148 1110
504 }
505  
506 74 my %rechash = %$record;
507 74 my $id = $rechash{AphiaID};
508  
509 # return if $record{status} =~ "deleted";
510 # print %rechash, "\n";
511  
512 74 ▶ print "\n", $spc, "WORMS ID $id \n" if $self->Format eq 'TEXT';
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "TEXT" 74 0 74
513 74 ▶ if ($first && $self->Format eq "SQL") {
Branch: 1 branch
BranchTrueFalseTotal
if ($first and $self->Format eq "SQL") 0 74 74
Condition66%2/3
$first and $self->Format eq "SQL"
!ll&&!rl&&r
7310
MC/DC0%0/2
$first and $self->Format eq "SQL"
$first $self->Format eq "SQL"
Truth table66%2/3
A and B
A= $firstB= $self->Format eq "SQL"
ABresult
0X0
100
111
514 0 print "INSERT INTO WORMS_TABLE\n(";
515 0 print join(",",@head), ") VALUES\n(";
516 }
517 74 ▶ if (!$first && $self->Format eq "SQL") {
Branch: 1 branch
BranchTrueFalseTotal
if (not $first and $self->Format eq "SQL") 0 74 74
Condition66%2/3
not $first and $self->Format eq "SQL"
!ll&&!rl&&r
1730
MC/DC0%0/2
not $first and $self->Format eq "SQL"
not $first $self->Format eq "SQL"
Truth table66%2/3
not(A) and B
A= not $firstB= $self->Format eq "SQL"
ABresult
0X0
100
111
518 0 print ",\n(";
519 }
520 74 ▶ if ($first && $self->Format eq "CSV") {
Branch: 1 branch
BranchTrueFalseTotal
if ($first and $self->Format eq "CSV") 0 74 74
Condition66%2/3
$first and $self->Format eq "CSV"
!ll&&!rl&&r
7310
MC/DC0%0/2
$first and $self->Format eq "CSV"
$first $self->Format eq "CSV"
Truth table66%2/3
A and B
A= $firstB= $self->Format eq "CSV"
ABresult
0X0
100
111
521 0 print join(",",@head), "\n";
522 }
523  
524 74 foreach my $k (keys %rechash) {
525 2072 my $value = $rechash{$k};
526 2072 ▶ $value //= '';
Condition100%2/2
$value //= ""
l!l
1798274
MC/DC100%1/1
$value //= ""
$value
Truth table100%2/2
A
A= $value
Aresult
11
00
527 2072 $value =~ s/'/\\'/g;
528 2072 my $i = $ORDER_HASH{$k};
529 2072 ▶ if (! defined($i)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $i) 962 1110 2072
530 962 ▶ print "NO MATCH ",$k,"\n" if $self->Debug > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->Debug > 2 0 962 962
531 962 next;
532 }
533 1110 ▶ if ($i>=0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 1110 0 1110
534 # $data[i] = sprintf("%16s %d %8s %16s %s%s%s",
535 # $k, $i, $TYPE[$i],$head[$i],$quote[$i], $value, $quote[$i])
536 1110 ▶ $data[$i] = sprintf("%s%8s %16s %s%s%s",
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "TEXT" 1110 0 1110
537 $spc, $TYPE[$i],$head[$i],$quote[$i], $value, $quote[$i])
538 if $self->Format eq "TEXT";
539  
540 1110 ▶ $data[$i] = $quote[$i].$value.$quote[$i]
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "SQL" 0 1110 1110
541 if $self->Format eq "SQL";
542  
543 1110 ▶ $data[$i] = $quote[$i].$value.$quote[$i]
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "CSV" 0 1110 1110
544 if $self->Format eq "CSV";
545 }
546 }
547 74 ▶ print join(",", @data), "\n" if $self->Format eq "CSV";
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "CSV" 0 74 74
548 74 ▶ print join(",", @data), ")" if !$last && $self->Format eq "SQL";
Branch: 1 branch
BranchTrueFalseTotal
if not $last and $self->Format eq "SQL" 0 74 74
Condition33%1/3
not $last and $self->Format eq "SQL"
!ll&&!rl&&r
7400
MC/DC0%0/2
not $last and $self->Format eq "SQL"
not $last $self->Format eq "SQL"
Truth table33%1/3
not(A) and B
A= not $lastB= $self->Format eq "SQL"
ABresult
0X0
100
111
549 74 ▶ print join(",", @data), ");\n" if $last && $self->Format eq "SQL";
Branch: 1 branch
BranchTrueFalseTotal
if $last and $self->Format eq "SQL" 0 74 74
Condition33%1/3
$last and $self->Format eq "SQL"
!ll&&!rl&&r
0740
MC/DC0%0/2
$last and $self->Format eq "SQL"
$last $self->Format eq "SQL"
Truth table33%1/3
A and B
A= $lastB= $self->Format eq "SQL"
ABresult
0X0
100
111
550 74 ▶ print join("\n", @data) if $self->Format eq "TEXT";
Branch: 1 branch
BranchTrueFalseTotal
if $self->Format eq "TEXT" 74 0 74
551 74 ▶ print "\n", $spc,"EOF\n" if $last && $self->Format eq "TEXT";
Branch: 1 branch
BranchTrueFalseTotal
if $last and $self->Format eq "TEXT" 74 0 74
Condition33%1/3
$last and $self->Format eq "TEXT"
!ll&&!rl&&r
0074
MC/DC0%0/2
$last and $self->Format eq "TEXT"
$last $self->Format eq "TEXT"
Truth table33%1/3
A and B
A= $lastB= $self->Format eq "TEXT"
ABresult
0X0
100
111
552 }
553  
554 # WORMS dump Data ------------------------------------------------------
555 3 ▶sub printRecordDef($self, $record, $spc) {
Subroutine printRecordDef: called CC=18 SCAR=28.9
Pod documented
556 3 my %rechash = %$record;
557 3 my $id = $rechash{AphiaID};
558 # return if $record{status} =~ "deleted";
559 # print %rechash, "\n";
560 3 print "\n", $spc, "WORMS ID $id \n";
561 3 foreach my $k (keys %rechash) {
562 84 my $value = $rechash{$k};
563 84 ▶ $value =~ s/'/\`\'/g if $value; # Franzoesische Authoren unerwuenscht
Branch: 1 branch
BranchTrueFalseTotal
if $value 69 15 84
564 84 ▶ print $spc, " INT APHIA.ID ", $value, "\n" if $k =~ m/^AphiaID/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^AphiaID/u 3 81 84
565 84 ▶ print $spc, " STR AUTHOR '",$value, "'\n" if $k =~ m/^authority/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^authority/u 3 81 84
566 84 ▶ print $spc, " STR NAME '",$value, "'\n" if $k =~ m/^scientificname/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^scientificname/u 3 81 84
567 84 ▶ print $spc, " STR RANK '",$value, "'\n" if $k =~ m/^rank/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^rank/u 3 81 84
568 84 ▶ print $spc, " STR STATUS '",$value, "'\n" if $k =~ m/^status/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^status/u 3 81 84
569 84 ▶ print $spc, " STR CITE '",$value, "'\n" if $k =~ m/^citation/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^citation/u 3 81 84
570 84 ▶ print $spc, " INT VALID.APHIA.ID ", $value, "\n" if $k =~ m/^valid_AphiaID/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^valid_AphiaID/u 3 81 84
571 84 ▶ print $spc, " STR VALID.NAME '",$value, "'\n" if $k =~ m/^valid_name/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^valid_name/u 3 81 84
572 84 ▶ print $spc, " STR VALID.AUTHOR '",$value, "'\n" if $k =~ m/^valid_authority/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^valid_authority/u 3 81 84
573 84 ▶ print $spc, " STR KINGDOM '",$value, "'\n" if $k =~ m/^kingdom/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^kingdom/u 3 81 84
574 84 ▶ print $spc, " STR PHYLUM '",$value, "'\n" if $k =~ m/^phylum/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^phylum/u 3 81 84
575 84 ▶ print $spc, " STR CLASS '",$value, "'\n" if $k =~ m/^class/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^class/u 3 81 84
576 84 ▶ print $spc, " STR ORDER '",$value, "'\n" if $k =~ m/^order/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^order/u 3 81 84
577 84 ▶ print $spc, " STR FAMILY '",$value, "'\n" if $k =~ m/^family/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^family/u 3 81 84
578 84 ▶ print $spc, " STR GENUS '",$value, "'\n" if $k =~ m/^genus/;
Branch: 1 branch
BranchTrueFalseTotal
if $k =~ /^genus/u 3 81 84
579 }
580 3 print $spc, "EOF \n";
581 3 1
582 }
583  
584 =head1 BUGS
585  
586 Please report bugs via the issue tracker: L<https://rt.cpan.org>.
587  
588 =cut
589  
590 =head1 AUTHOR
591  
592 Alexander Weidauer E<lt>alex.weidauer@huckfinn.deE<gt>
593  
594 =head1 COPYRIGHT AND LICENSE
595  
596 Copyright (C) 2012 by Alexander Weidauer
597  
598 This program is free software: you can redistribute it and/or modify it
599 under the terms of the GNU General Public License as published by the
600 Free Software Foundation, either version 3 of the License, or any later
601 version.
602  
603 This program is distributed in the hope that it will be useful, but
604 WITHOUT ANY WARRANTY; without even the implied warranty of
605 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
606 General Public License for more details.
607  
608 You should have received a copy of the GNU General Public License along
609 with this program. If not, see <http://www.gnu.org/licenses/>.
610  
611 =cut
612  
613 3 1;
614  
615 # EOF ==================================================================
↑ Summary