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