Tools/EUtilities.pm

filter: Statementstmt 59.6% 236 / 396 Branchbran 42.9% 115 / 268 Conditioncond 35.7% 25 / 70 MC/DCmcdc 11.6% 5 / 43 Subroutinesub 67.1% 43 / 64 Podpod 98.0% 50 / 51 totaltotal 53.1% 474 / 892 CC 164 SCAR 34.5
CC
164
Cov
51%
_print_handler
210.0
parse_chunk
132.0
parse_data
62.6
CRAP 31.6
« Tools/EUtilities/Query.pm ↑ Summary Tools/EUtilities/EUtilParameters.pm »
1 package Bio::Tools::EUtilities;
2 19 our $AUTHORITY = 'cpan:BIOPERLML';
3 19 $Bio::Tools::EUtilities::VERSION = '1.74';
4 19 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use base qw(Bio::Root::IO Bio::Tools::EUtilities::EUtilDataI);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 # ABSTRACT: NCBI eutil XML parsers.
11 # AUTHOR: Chris Fields <cjfields@bioperl.org>
12 # OWNER: 2006-2013 Chris Fields
13 # LICENSE: Perl_5
14  
15  
16  
17  
18 {
19  
20 19 my %DATA_MODULE = (
21 'esearch' => 'Query',
22 'egquery' => 'Query',
23 'espell' => 'Query',
24 'epost' => 'Query',
25 'elink' => 'Link',
26 'einfo' => 'Info',
27 'esummary' => 'Summary',
28 );
29  
30 sub new {
31 44 ▶ my($caller,@args) = @_;
Subroutine new: called CC=5 SCAR=16.7
Pod documented
32 44 ▶ my $class = ref $caller || $caller;
Condition33%1/3
ref $caller || $caller
l!l&&r!l&&!r
0440
MC/DC0%0/2
ref $caller || $caller
ref $caller $caller
Truth table33%1/3
A || B
A= ref $callerB= $caller
ABresult
1X1
011
000
33 44 ▶ if ($class =~ m{Bio::Tools::EUtilities::(\S+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class =~ /Bio::Tools::EUtilities::(\S+)/) { } 22 22 44
34 22 my ($self) = $class->SUPER::new(@args);
35 22 $self->_initialize(@args);
36 22 return $self;
37 } else {
38 22 my %param = @args;
39 22 @param{ map { lc $_ } keys %param } = values %param; # lowercase keys
40 22 ▶ my $eutil = $param{'-eutil'} || $class->throw("Need eutil to make instance");
Condition33%1/3
$param{'-eutil'} || $class->throw('Need eutil to make instance')
l!l&&r!l&&!r
2200
MC/DC0%0/2
$param{'-eutil'} || $class->throw('Need eutil to make instance')
$param{'-eutil'} $class->throw('Need eutil to make instance')
Truth table33%1/3
A || B
A= $param{'-eutil'}B= $class->throw('Need eutil to make instance')
ABresult
1X1
011
000
41 22 ▶ return unless( $class->_load_eutil_module( $DATA_MODULE{$eutil}) );
Branch: 1 branch
BranchTrueFalseTotal
unless $class->_load_eutil_module($DATA_MODULE{$eutil}) 0 22 22
42 22 return "Bio::Tools::EUtilities::$DATA_MODULE{$eutil}"->new(-datatype => lc $DATA_MODULE{$eutil},
43 -eutil => $eutil,
44 @args);
45 }
46 }
47  
48 sub _initialize {
49 22 ▶ my ($self, @args) = @_;
Subroutine _initialize: called CC=8 SCAR=21.2
50 22 my ($response, $pobj, $type, $eutil, $cache, $lazy) =
51 $self->_rearrange([qw(RESPONSE
52 PARAMETERS
53 DATATYPE
54 EUTIL
55 CACHE_RESPONSE
56 LAZY)], @args);
57 22 ▶ $lazy ||= 0;
Condition50%1/2
$lazy ||= 0
l!l
022
MC/DC0%0/1
$lazy ||= 0
$lazy
Truth table50%1/2
A
A= $lazy
Aresult
11
00
58 22 ▶ $cache ||= 0;
Condition50%1/2
$cache ||= 0
l!l
022
MC/DC0%0/1
$cache ||= 0
$cache
Truth table50%1/2
A
A= $cache
Aresult
11
00
59 22 $self->datatype($type);
60 22 $self->eutil($eutil);
61 # lazy parsing only implemented for elink and esummary (where returned data
62 # can be quite long). Also, no point to parsing lazily when the data is
63 # already in memory in an HTTP::Response object, so turn it off and chunk
64 # the Response object after parsing.
65 22 ▶ $response && $self->response($response);
Branch: 1 branch
BranchTrueFalseTotal
$response and $self->response($response) 0 22 22
66 22 ▶ $pobj && $self->parameter_base($pobj);
Branch: 1 branch
BranchTrueFalseTotal
$pobj and $self->parameter_base($pobj) 0 22 22
67 22 $self->cache_response($cache);
68 22 ▶ $lazy = 0 if ($response) || ($eutil ne 'elink' && $eutil ne 'esummary');
Branch: 1 branch
BranchTrueFalseTotal
if $response or $eutil ne "elink" and $eutil ne "esummary" 7 15 22
Condition83%5/6
$response or $eutil ne "elink" and $eutil ne "esummary"
l!l&&r!l&&!r
0715
$eutil ne "elink" and $eutil ne "esummary"
!ll&&!rl&&r
1327
MC/DC33%1/3
$response or $eutil ne "elink" and $eutil ne "esummary"
$response $eutil ne "elink" $eutil ne "esummary"
Truth table50%2/4
A or B and C
A= $responseB= $eutil ne "elink"C= $eutil ne "esummary"
ABCresult
1XX1
0111
00X0
0100
69 # setting parser to 'lazy' mode is permanent (can't reset later)
70 22 $self->{'_lazy'} = $lazy;
71 22 $self->{'_parsed'} = 0;
72 }
73  
74 }
75  
76  
77 19 sub cache_response {
78 44 ▶ my ($self, $cache) = @_;
Subroutine cache_response: called CC=3 SCAR=11.0
Pod documented
79 44 ▶ if (defined $cache) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cache) 22 22 44
80 22 ▶ $self->{'_cache_response'} = ($cache) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cache ? : 0 22 22
81 }
82 44 return $self->{'_cache_response'};
83 }
84  
85  
86 sub response {
87 22 ▶ my ($self, $response) = @_;
Subroutine response: called CC=4 SCAR=21.7
Pod documented
88 22 ▶ if ($response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response) 0 22 22
89 0 ▶ $self->throw('Not an HTTP::Response object') unless (ref $response && $response->isa('HTTP::Response'));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response and $response->isa("HTTP::Response") 0 0 0
Condition0%0/3
ref $response and $response->isa("HTTP::Response")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $response and $response->isa("HTTP::Response")
ref $response $response->isa("HTTP::Response")
Truth table0%0/3
A and B
A= ref $responseB= $response->isa("HTTP::Response")
ABresult
0X0
100
111
90 0 $self->{'_response'} = $response;
91 }
92 22 return $self->{'_response'};
93 }
94  
95  
96 sub parameter_base {
97 34 ▶ my ($self, $pb) = @_;
Subroutine parameter_base: called CC=6 SCAR=19.9
Pod documented
98 34 ▶ if ($pb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pb) 4 30 34
99 4 ▶ $self->throw('Not an Bio::ParameterBaseI object') unless (ref $pb && $pb->isa('Bio::ParameterBaseI'));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pb and $pb->isa("Bio::ParameterBaseI") 0 4 4
Condition33%1/3
ref $pb and $pb->isa("Bio::ParameterBaseI")
!ll&&!rl&&r
004
MC/DC0%0/2
ref $pb and $pb->isa("Bio::ParameterBaseI")
ref $pb $pb->isa("Bio::ParameterBaseI")
Truth table33%1/3
A and B
A= ref $pbB= $pb->isa("Bio::ParameterBaseI")
ABresult
0X0
100
111
100 4 ▶ $self->warn('Not an Bio::Tools::EUtilities::EUtilParameters object; may experience some turbulence...') unless (ref $pb && $pb->isa('Bio::Tools::EUtilities::EUtilParameters'));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pb and $pb->isa("Bio::Tools::EUtilities::EUtilParameters") 0 4 4
Condition33%1/3
ref $pb and $pb->isa("Bio::Tools::EUtilities::EUtilParameters")
!ll&&!rl&&r
004
MC/DC0%0/2
ref $pb and $pb->isa("Bio::Tools::EUtilities::EUtilParameters")
ref $pb $pb->isa("Bio::Tools::EUtilities::EUtilParameters")
Truth table33%1/3
A and B
A= ref $pbB= $pb->isa("Bio::Tools::EUtilities::EUtilParameters")
ABresult
0X0
100
111
101 4 $self->{'_parameter_base'} = $pb;
102 }
103 34 return $self->{'_parameter_base'};
104 }
105  
106  
107 sub data_parsed {
108 188 ▶ return shift->{'_parsed'};
Subroutine data_parsed: called CC=1 SCAR=0.0
Pod documented
109 }
110  
111  
112 sub is_lazy {
113 83 ▶ return shift->{'_lazy'};
Subroutine is_lazy: called CC=1 SCAR=0.0
Pod documented
114 }
115  
116  
117 {
118 19 my %EUTIL_DATA = (
119 'esummary' => [qw(DocSum Item)],
120 'epost' => [],
121 'egquery' => [],
122 'einfo' => [qw(Field Link)],
123 'elink' => [qw(LinkSet LinkSetDb LinkSetDbHistory IdUrlSet
124 Id IdLinkSet ObjUrl Link LinkInfo)],
125 'espell' => [qw(Original Replaced)],
126 'esearch' => [qw(Id ErrorList WarningList)],
127 );
128  
129 sub parse_data {
130 22 ▶ my $self = shift;
Subroutine parse_data: called CC=16 SCAR=41.4
Pod documented
131 22 my $eutil = $self->eutil;
132 22 my $xs = XML::Simple->new();
133 22 ▶ my $response = $self->response ? $self->response :
Branch: 2 branches
BranchTrueFalseTotal
$self->response ? : 0 22 22
$self->_fh ? : 22 0 22
134 $self->_fh ? $self->_fh :
135 $self->throw('No response or stream specified');
136 my $simple = ($eutil eq 'espell') ?
137 $xs->XMLin($self->_fix_espell($response), forcearray => $EUTIL_DATA{$eutil}) :
138 ($response && $response->isa("HTTP::Response")) ?
139 $xs->XMLin($response->content, forcearray => $EUTIL_DATA{$eutil}) :
140 22 ▶ $xs->XMLin($response, forcearray => $EUTIL_DATA{$eutil});
Branch: 2 branches
BranchTrueFalseTotal
$eutil eq 'espell' ? : 1 21 22
$response && $response->isa('HTTP::Response') ? : 0 21 21
Condition33%1/3
$response and $response->isa("HTTP::Response")
!ll&&!rl&&r
0210
MC/DC0%0/2
$response and $response->isa("HTTP::Response")
$response $response->isa("HTTP::Response")
Truth table33%1/3
A and B
A= $responseB= $response->isa("HTTP::Response")
ABresult
0X0
100
111
141 # check for errors
142 22 ▶ if ($simple->{ERROR}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple->{"ERROR"}) 1 21 22
143 1 my $error = $simple->{ERROR};
144 1 ▶ $self->throw("NCBI $eutil fatal error: ".$error) unless ref $error;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $error 0 1 1
145 }
146 22 ▶ if ($simple->{InvalidIdList}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple->{"InvalidIdList"}) 0 22 22
147 0 $self->warn("NCBI $eutil error: Invalid ID List".$simple->{InvalidIdList});
148 0 return;
149 }
150 22 ▶ if ($simple->{ErrorList} || $simple->{WarningList}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($simple->{"ErrorList"} or $simple->{"WarningList"}) 0 22 22
Condition33%1/3
$simple->{"ErrorList"} or $simple->{"WarningList"}
l!l&&r!l&&!r
0022
MC/DC0%0/2
$simple->{"ErrorList"} or $simple->{"WarningList"}
$simple->{"ErrorList"} $simple->{"WarningList"}
Truth table33%1/3
A or B
A= $simple->{"ErrorList"}B= $simple->{"WarningList"}
ABresult
1X1
011
000
151 0 ▶ my @errorlist = @{ $simple->{ErrorList} } if $simple->{ErrorList};
Branch: 1 branch
BranchTrueFalseTotal
if $simple->{"ErrorList"} 0 0 0
152 0 ▶ my @warninglist = @{ $simple->{WarningList} } if $simple->{WarningList};
Branch: 1 branch
BranchTrueFalseTotal
if $simple->{"WarningList"} 0 0 0
153 0 my ($err_warn);
154 0 for my $error (@errorlist) {
155 0 my $messages = join("\n\t",map {"$_ [".$error->{$_}.']'}
156 0 grep {!ref $error->{$_}} keys %$error);
157 0 $err_warn .= "Error : $messages";
158 }
159 0 for my $warn (@warninglist) {
160 0 my $messages = join("\n\t",map {"$_ [".$warn->{$_}.']'}
161 0 grep {!ref $warn->{$_}} keys %$warn);
162 0 $err_warn .= "Warnings : $messages";
163 }
164 0 chomp($err_warn);
165 0 $self->warn("NCBI $eutil Errors/Warnings:\n".$err_warn)
166 # don't return as some data may still be useful
167 }
168 22 ▶ delete $self->{'_response'} unless $self->cache_response;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->cache_response 22 0 22
169 22 $self->{'_parsed'} = 1;
170 22 $self->_add_data($simple);
171 }
172  
173 # implemented only for elink/esummary, still experimental
174  
175 sub parse_chunk {
176 0 ▶ my $self = shift;
Subroutine parse_chunk: not called CC=11 SCAR=48.8
Pod undocumented
177 0 my $eutil = $self->eutil;
178 0 ▶ my $tag = $eutil eq 'elink' ? 'LinkSet' :
Branch: 2 branches
BranchTrueFalseTotal
$eutil eq 'elink' ? : 0 0 0
$eutil eq 'esummary' ? : 0 0 0
179 $eutil eq 'esummary' ? 'DocSum' :
180 $self->throw("Only eutil elink/esummary use parse_chunk()");
181 0 my $xs = XML::Simple->new();
182 0 ▶ if ($self->response) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->response) { } 0 0 0
183 0 $self->throw("Lazy parsing not implemented for HTTP::Response data yet");
184 0 ▶ delete $self->{'_response'} if !$self->cache_response && $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->cache_response and $self->data_parsed 0 0 0
Condition0%0/3
not $self->cache_response and $self->data_parsed
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->cache_response and $self->data_parsed
not $self->cache_response $self->data_parsed
Truth table0%0/3
not(A) and B
A= not $self->cache_responseB= $self->data_parsed
ABresult
0X0
100
111
185 } else { # has to be a file/filehandle
186 0 my $fh = $self->_fh;
187 0 my ($chunk, $seendoc, $line);
188 CHUNK:
189 0 ▶ while ($line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $fh)) 0 0 0
190 0 ▶ next unless $seendoc || $line =~ m{^<$tag>};
Branch: 1 branch
BranchTrueFalseTotal
unless $seendoc or $line =~ /^<$tag>/ 0 0 0
Condition0%0/3
$seendoc or $line =~ /^<$tag>/
l!l&&r!l&&!r
000
MC/DC0%0/2
$seendoc or $line =~ /^<$tag>/
$seendoc $line =~ /^<$tag>/
Truth table0%0/3
A or B
A= $seendocB= $line =~ /^<$tag>/
ABresult
1X1
011
000
191 0 $seendoc = 1;
192 0 $chunk .= $line;
193 0 ▶ last if $line =~ m{^</$tag>};
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ m[^</$tag>] 0 0 0
194 }
195 0 ▶ if (!defined $line) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $line) 0 0 0
196 0 $self->{'_parsed'} = 1;
197 0 return;
198 }
199 $self->_add_data(
200 0 $xs->XMLin($chunk, forcearray => $EUTIL_DATA{$eutil}, KeepRoot => 1)
201 );
202 }
203 }
204  
205 }
206  
207  
208 19 sub to_string {
209 0 ▶ my $self = shift;
Subroutine to_string: not called CC=3 SCAR=24.8
Pod documented
210 0 ▶ $self->parse_data if ($self->can('parse_data') && !$self->data_parsed);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("parse_data") and not $self->data_parsed 0 0 0
Condition0%0/3
$self->can("parse_data") and not $self->data_parsed
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can("parse_data") and not $self->data_parsed
$self->can("parse_data") not $self->data_parsed
Truth table0%0/3
A and not(B)
A= $self->can("parse_data")B= not $self->data_parsed
ABresult
0X0
100
111
211 0 return sprintf("%-20s:%s\n\n", 'EUtil', $self->eutil);
212 }
213  
214  
215 sub print_all {
216 0 ▶ my ($self, @args) = @_;
Subroutine print_all: not called CC=1 SCAR=6.9
Pod documented
217 0 $self->_print_handler(@args);
218 }
219  
220  
221  
222  
223 sub get_ids {
224 23 ▶ my ($self, $request) = @_;
Subroutine get_ids: called CC=13 SCAR=26.6
Pod documented
225 23 my $eutil = $self->eutil;
226 23 ▶ if ($self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_lazy) 0 23 23
227 0 $self->warn('get_ids() not implemented when using lazy mode');
228 0 return;
229 }
230 23 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 23 23
231 23 ▶ if ($eutil eq 'esearch') {
Branch: 4 branches
BranchTrueFalseTotal
if ($eutil eq 'esearch') { } 2 21 23
elsif ($eutil eq 'elink') { } 15 6 21
elsif ($eutil eq 'esummary') { } 2 4 6
elsif (my $pb = $self->parameter_base) { } 1 3 4
232 2 ▶ return $self->{'_id'} ? @{ $self->{'_id'} } : ();
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_id'} ? : 2 0 2
233 } elsif ($eutil eq 'elink') {
234 15 my @ids;
235 15 ▶ if ($request) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request) { } 4 11 15
236 4 ▶ if (ref $request eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $request eq 'CODE') { } 0 4 4
237 0 push @ids, map {$_->get_ids }
238 0 grep { $request->($_) } $self->get_LinkSets;
239 } else {
240 push @ids,
241 14 map { @{$_->[0]} }
242 16 grep {grep { $_ eq $request } @{$_->[1]}}
243 4 map {[[$_->get_ids], [$_->get_databases]]} $self->get_LinkSets;
244 }
245 } else {
246 11 ▶ $self->warn('Multiple database present, IDs will be globbed together')
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_linked_databases > 1 0 11 11
247 if $self->get_linked_databases > 1;
248 11 push @ids, map {$_->get_ids } $self->get_LinkSets;
249 }
250 15 return @ids;
251 } elsif ($eutil eq 'esummary') {
252 2 ▶ unless (exists $self->{'_id'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_id"}) 2 0 2
253 2 push @{$self->{'_id'}}, map {$_->get_id } $self->get_DocSums;
254 }
255 2 return @{$self->{'_id'}};
256 } elsif (my $pb = $self->parameter_base) {
257 1 my $ids = $pb->id;
258 1 ▶ return $ids ? @{$ids} : ();
Branch: 1 branch
BranchTrueFalseTotal
$ids ? : 1 0 1
259 } else {
260 return ()
261 3 }
262 }
263  
264  
265 sub get_database {
266 16 ▶ return ($_[0]->get_databases)[0];
Subroutine get_database: called CC=1 SCAR=0.0
Pod documented
267 }
268  
269  
270 sub get_db {
271 8 ▶ return shift->get_database;
Subroutine get_db: called CC=1 SCAR=0.0
Pod documented
272 }
273  
274  
275 sub get_databases {
276 51 ▶ my ($self, $db) = @_;
Subroutine get_databases: called CC=10 SCAR=23.1
Pod documented
277 51 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 18 33 51
278 51 my $eutil = $self->eutil;
279 51 my @dbs;
280 51 ▶ if ($eutil eq 'einfo' || $eutil eq 'espell') {
Branch: 4 branches
BranchTrueFalseTotal
if ($eutil eq 'einfo' or $eutil eq 'espell') { } 12 39 51
elsif ($eutil eq 'egquery') { } 3 36 39
elsif ($eutil eq 'elink') { } 24 12 36
elsif ($self->parameter_base) { } 5 7 12
Condition100%3/3
$eutil eq "einfo" or $eutil eq "espell"
l!l&&r!l&&!r
4839
MC/DC100%2/2
$eutil eq "einfo" or $eutil eq "espell"
$eutil eq "einfo" $eutil eq "espell"
Truth table100%3/3
A or B
A= $eutil eq "einfo"B= $eutil eq "espell"
ABresult
1X1
011
000
281 @dbs = $self->{'_dbname'} ||
282 12 ▶ $self->{'_database'} ||
Condition83%5/6
$self->{'_dbname'} || $self->{'_database'} || $self->get_available_databases
l!l&&r!l&&!r
1020
$self->{"_dbname"} or $self->{"_database"}
l!l&&r!l&&!r
282
MC/DC0%0/3
$self->{'_dbname'} || $self->{'_database'} || $self->get_available_databases
$self->{"_dbname"} $self->{"_database"} $self->get_available_databases
Truth table75%3/4
A or B || C
A= $self->{"_dbname"}B= $self->{"_database"}C= $self->get_available_databases
ABCresult
1XX1
01X1
0011
0000
283 $self->get_available_databases;
284 } elsif ($eutil eq 'egquery') {
285 3 @dbs = map {$_->get_database} ($self->get_GlobalQueries);
286 } elsif ($eutil eq 'elink') {
287 # only unique dbs
288 24 my %tmp;
289 114 @dbs = sort grep {!$tmp{$_}++}
290 24 map {($_->get_databases)} $self->get_LinkSets;
291 } elsif ($self->parameter_base) {
292 5 ▶ if ($self->parameter_base->eutil eq 'elink') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->parameter_base->eutil eq 'elink') { } 0 5 5
293 0 @dbs = $self->parameter_base->dbfrom;
294 } else {
295 5 @dbs = $self->parameter_base->db;
296 }
297 }
298 51 return @dbs;
299 }
300  
301  
302 sub get_dbs {
303 3 ▶ return shift->get_databases;
Subroutine get_dbs: called CC=1 SCAR=0.0
Pod documented
304 }
305  
306  
307 sub next_History {
308 4 ▶ my $self = shift;
Subroutine next_History: called CC=3 SCAR=11.0
Pod documented
309 4 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 1 3 4
310 $self->{'_histories_it'} = $self->generate_iterator('histories')
311 4 ▶ if (!exists $self->{'_histories_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_histories_it"} 4 0 4
312 4 my $hist = $self->{'_histories_it'}->();
313 }
314  
315  
316 sub next_cookie {
317 0 ▶ return shift->next_History;
Subroutine next_cookie: not called CC=1 SCAR=6.9
Pod documented
318 }
319  
320  
321 sub get_Histories {
322 0 ▶ my $self = shift;
Subroutine get_Histories: not called CC=3 SCAR=24.8
Pod documented
323 0 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 0 0
324 0 ▶ ref $self->{'_histories'} ? return @{ $self->{'_histories'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_histories'} ? : 0 0 0
325 }
326  
327  
328 sub get_count {
329 6 ▶ my ($self, $db) = @_;
Subroutine get_count: called CC=6 SCAR=19.1
Pod documented
330 6 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 2 4 6
331 # egquery
332 6 ▶ if ($self->datatype eq 'multidbquery') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->datatype eq 'multidbquery') { } 3 3 6
333 3 ▶ if (!$db) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($db) 0 3 3
334 0 $self->warn('Must specify database to get count from');
335 0 return;
336 }
337 3 my ($gq) = grep {$_->get_database eq $db} $self->get_GlobalQueries;
338 3 ▶ $gq && return $gq->get_count;
Branch: 1 branch
BranchTrueFalseTotal
$gq and return $gq->get_count 3 0 3
339 0 $self->warn("Unknown database $db");
340 0 return;
341 } else {
342 3 ▶ return $self->{'_count'} || scalar($self->get_ids);
Condition100%2/2
$self->{'_count'} || scalar $self->get_ids
l!l
21
MC/DC100%1/1
$self->{'_count'} || scalar $self->get_ids
$self->{'_count'}
Truth table100%2/2
A
A= $self->{'_count'}
Aresult
11
00
343 }
344 }
345  
346  
347 sub get_term {
348 6 ▶ my ($self, @args) = @_;
Subroutine get_term: called CC=5 SCAR=16.1
Pod documented
349 6 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 6 6
350 $self->{'_term'} ? $self->{'_term'} :
351 6 ▶ $self->{'_query'} ? $self->{'_query'} :
Branch: 3 branches
BranchTrueFalseTotal
$self->{'_term'} ? : 1 5 6
$self->{'_query'} ? : 2 3 5
$self->parameter_base ? : 1 2 3
352 $self->parameter_base ? $self->parameter_base->term :
353 return;
354 }
355  
356  
357 sub get_translation_from {
358 3 ▶ my $self = shift;
Subroutine get_translation_from: called CC=2 SCAR=7.1
Pod documented
359 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 3 3
360 3 return $self->{'_translation'}->{'From'};
361 }
362  
363  
364 sub get_translation_to {
365 3 ▶ my $self = shift;
Subroutine get_translation_to: called CC=2 SCAR=7.1
Pod documented
366 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 3 3
367 3 return $self->{'_translation'}->{'To'};
368 }
369  
370  
371 sub get_retstart {
372 3 ▶ my $self = shift;
Subroutine get_retstart: called CC=2 SCAR=7.1
Pod documented
373 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 3 3
374 3 return $self->{'_retstart'};
375 }
376  
377  
378 sub get_retmax {
379 3 ▶ my $self = shift;
Subroutine get_retmax: called CC=2 SCAR=7.1
Pod documented
380 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 3 3
381 3 return $self->{'_retmax'};
382 }
383  
384  
385 sub get_query_translation {
386 0 ▶ my $self = shift;
Subroutine get_query_translation: not called CC=2 SCAR=17.9
Pod documented
387 0 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 0 0
388 0 return $self->{'_querytranslation'};
389 }
390  
391  
392 sub get_corrected_query {
393 3 ▶ my $self = shift;
Subroutine get_corrected_query: called CC=2 SCAR=7.1
Pod documented
394 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 3 3
395 3 return $self->{'_correctedquery'};
396 }
397  
398  
399 sub get_replaced_terms {
400 4 ▶ my $self = shift;
Subroutine get_replaced_terms: called CC=5 SCAR=16.6
Pod documented
401 4 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 4 4
402 4 ▶ if ($self->{'_spelledquery'} && $self->{'_spelledquery'}->{Replaced}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_spelledquery"} and $self->{"_spelledquery"}{"Replaced"}) 2 2 4
Condition66%2/3
$self->{"_spelledquery"} and $self->{"_spelledquery"}{"Replaced"}
!ll&&!rl&&r
202
MC/DC50%1/2
$self->{"_spelledquery"} and $self->{"_spelledquery"}{"Replaced"}
$self->{"_spelledquery"} $self->{"_spelledquery"}{"Replaced"}
Truth table66%2/3
A and B
A= $self->{"_spelledquery"}B= $self->{"_spelledquery"}{"Replaced"}
ABresult
0X0
100
111
403 ref $self->{'_spelledquery'}->{Replaced} ?
404 2 ▶ return @{ $self->{'_spelledquery'}->{Replaced} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_spelledquery'}{'Replaced'} ? : 2 0 2
405 }
406 }
407  
408  
409 sub next_GlobalQuery {
410 0 ▶ my $self = shift;
Subroutine next_GlobalQuery: not called CC=3 SCAR=24.8
Pod documented
411 0 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 0 0
412 $self->{'_globalqueries_it'} = $self->generate_iterator('globalqueries')
413 0 ▶ if (!exists $self->{'_globalqueries_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_globalqueries_it"} 0 0 0
414 0 $self->{'_globalqueries_it'}->();
415 }
416  
417  
418 sub get_GlobalQueries {
419 8 ▶ my $self = shift;
Subroutine get_GlobalQueries: called CC=3 SCAR=11.0
Pod documented
420 8 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 8 8
421 8 ▶ ref $self->{'_globalqueries'} ? return @{ $self->{'_globalqueries'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_globalqueries'} ? : 7 1 8
422 }
423  
424  
425 sub print_GlobalQueries {
426 0 ▶ my ($self, @args) = @_;
Subroutine print_GlobalQueries: not called CC=1 SCAR=6.9
Pod documented
427 0 $self->_print_handler(@args, -type => 'GlobalQuery');
428 }
429  
430  
431 sub next_DocSum {
432 0 ▶ my $self = shift;
Subroutine next_DocSum: not called CC=4 SCAR=30.0
Pod documented
433 0 ▶ if(!$self->data_parsed && !$self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->data_parsed or $self->is_lazy) 0 0 0
Condition0%0/3
$self->data_parsed or $self->is_lazy
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->data_parsed or $self->is_lazy
$self->data_parsed $self->is_lazy
Truth table0%0/3
A or B
A= $self->data_parsedB= $self->is_lazy
ABresult
1X1
011
000
434 0 $self->parse_data;
435 }
436 $self->{'_docsums_it'} = $self->generate_iterator('docsums')
437 0 ▶ if (!exists $self->{'_docsums_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_docsums_it"} 0 0 0
438 0 $self->{'_docsums_it'}->();
439 }
440  
441  
442 sub get_DocSums {
443 4 ▶ my $self = shift;
Subroutine get_DocSums: called CC=4 SCAR=15.9
Pod documented
444 4 ▶ if ($self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_lazy) 0 4 4
445 0 $self->warn('get_DocSums() not implemented when using lazy mode');
446 0 return ();
447 }
448 4 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 4 4
449 4 ▶ return ref $self->{'_docsums'} ? @{ $self->{'_docsums'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_docsums'} ? : 4 0 4
450 }
451  
452  
453 sub print_DocSums {
454 0 ▶ my ($self, @args) = @_;
Subroutine print_DocSums: not called CC=1 SCAR=6.9
Pod documented
455 0 $self->_print_handler(@args, -type => 'DocSum');
456 }
457  
458  
459 sub get_available_databases {
460 3 ▶ my $self = shift;
Subroutine get_available_databases: called CC=3 SCAR=11.0
Pod documented
461 3 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 1 2 3
462 ($self->{'_available_databases'}) ?
463 3 ▶ return @{($self->{'_available_databases'})} :
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_available_databases'} ? : 3 0 3
464 return ();
465 }
466  
467  
468 sub get_record_count {
469 2 ▶ my $self = shift;
Subroutine get_record_count: called CC=2 SCAR=7.1
Pod documented
470 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
471 2 return $self->{'_count'}
472 }
473  
474  
475 sub get_last_update {
476 2 ▶ my $self = shift;
Subroutine get_last_update: called CC=2 SCAR=7.1
Pod documented
477 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
478 2 return $self->{'_lastupdate'}
479 }
480  
481  
482 sub get_menu_name {
483 2 ▶ my $self = shift;
Subroutine get_menu_name: called CC=4 SCAR=14.3
Pod documented
484 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
485 exists $self->{'_menuname'} ? return $self->{'_menuname'} :
486 2 ▶ exists $self->{'_menu'} ? return $self->{'_menu'} :
Branch: 2 branches
BranchTrueFalseTotal
exists $self->{'_menuname'} ? : 1 1 2
exists $self->{'_menu'} ? : 0 1 1
487 return;
488 }
489  
490  
491 sub get_description {
492 2 ▶ my $self = shift;
Subroutine get_description: called CC=2 SCAR=7.1
Pod documented
493 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
494 2 return $self->{'_description'};
495 }
496  
497  
498 sub next_FieldInfo {
499 0 ▶ my $self = shift;
Subroutine next_FieldInfo: not called CC=3 SCAR=24.8
Pod documented
500 0 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 0 0
501 $self->{'_fieldinfo_it'} = $self->generate_iterator('fieldinfo')
502 0 ▶ if (!exists $self->{'_fieldinfo_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_fieldinfo_it"} 0 0 0
503 0 $self->{'_fieldinfo_it'}->();
504 }
505  
506  
507 sub get_FieldInfo {
508 2 ▶ my $self = shift;
Subroutine get_FieldInfo: called CC=3 SCAR=11.0
Pod documented
509 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
510 2 ▶ return ref $self->{'_fieldinfo'} ? @{ $self->{'_fieldinfo'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_fieldinfo'} ? : 1 1 2
511 }
512  
513 19 *get_FieldInfos = \&get_FieldInfo;
514  
515  
516 sub next_LinkInfo {
517 0 ▶ my $self = shift;
Subroutine next_LinkInfo: not called CC=3 SCAR=24.8
Pod documented
518 0 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 0 0
519 $self->{'_linkinfo_it'} = $self->generate_iterator('linkinfo')
520 0 ▶ if (!exists $self->{'_linkinfo_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_linkinfo_it"} 0 0 0
521 0 $self->{'_linkinfo_it'}->();
522 }
523  
524  
525 sub get_LinkInfo {
526 2 ▶ my $self = shift;
Subroutine get_LinkInfo: called CC=3 SCAR=11.0
Pod documented
527 2 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 2 2
528 2 ▶ return ref $self->{'_linkinfo'} ? @{ $self->{'_linkinfo'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_linkinfo'} ? : 1 1 2
529 }
530  
531 19 *get_LinkInfos = \&get_LinkInfo;
532  
533  
534 sub print_FieldInfo {
535 0 ▶ my ($self, @args) = @_;
Subroutine print_FieldInfo: not called CC=1 SCAR=6.9
Pod documented
536 0 $self->_print_handler(@args, -type => 'FieldInfo');
537 }
538  
539  
540 sub print_LinkInfo {
541 0 ▶ my ($self, @args) = @_;
Subroutine print_LinkInfo: not called CC=1 SCAR=6.9
Pod documented
542 0 $self->_print_handler(@args, -type => 'LinkInfo');
543 }
544  
545  
546 sub next_LinkSet {
547 0 ▶ my $self = shift;
Subroutine next_LinkSet: not called CC=4 SCAR=30.0
Pod documented
548 #$self->parse_data unless $self->data_parsed;
549 0 ▶ if(!$self->data_parsed && !$self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->data_parsed or $self->is_lazy) 0 0 0
Condition0%0/3
$self->data_parsed or $self->is_lazy
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->data_parsed or $self->is_lazy
$self->data_parsed $self->is_lazy
Truth table0%0/3
A or B
A= $self->data_parsedB= $self->is_lazy
ABresult
1X1
011
000
550 0 $self->parse_data;
551 }
552 $self->{'_linksets_it'} = $self->generate_iterator('linksets')
553 0 ▶ if (!exists $self->{'_linksets_it'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_linksets_it"} 0 0 0
554 0 $self->{'_linksets_it'}->();
555 }
556  
557  
558 # add support for retrieval of data if lazy parsing is enacted
559  
560 sub get_LinkSets {
561 52 ▶ my $self = shift;
Subroutine get_LinkSets: called CC=4 SCAR=15.9
Pod documented
562 52 ▶ if ($self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_lazy) 0 52 52
563 0 $self->warn('get_LinkSets() not implemented when using lazy mode');
564 0 return ();
565 }
566 52 ▶ $self->parse_data unless $self->data_parsed;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->data_parsed 0 52 52
567 52 ▶ return ref $self->{'_linksets'} ? @{ $self->{'_linksets'} } : return ();
Branch: 1 branch
BranchTrueFalseTotal
ref $self->{'_linksets'} ? : 52 0 52
568 }
569  
570  
571 sub print_LinkSets {
572 0 ▶ my ($self, @args) = @_;
Subroutine print_LinkSets: not called CC=1 SCAR=6.9
Pod documented
573 0 $self->_print_handler(@args, -type => 'LinkSet');
574 }
575  
576  
577 sub get_linked_databases {
578 11 ▶ my $self = shift;
Subroutine get_linked_databases: called CC=2 SCAR=8.1
Pod documented
579 11 ▶ return $self->get_databases if $self->eutil eq 'elink';
Branch: 1 branch
BranchTrueFalseTotal
if $self->eutil eq "elink" 11 0 11
580 0 return ();
581 }
582  
583  
584 {
585 19 my %VALID_ITERATORS = (
586 'globalqueries' => 'globalqueries',
587 'fieldinfo' => 'fieldinfo',
588 'fieldinfos' => 'fieldinfo',
589 'linkinfo' => 'linkinfo',
590 'linkinfos' => 'linkinfo',
591 'linksets' => 'linksets',
592 'docsums' => 'docsums',
593 'histories' => 'histories'
594 );
595  
596  
597 sub rewind {
598 0 ▶ my ($self, $arg) = ($_[0], lc $_[1]);
Subroutine rewind: not called CC=7 SCAR=40.3
Pod documented
599 0 my $eutil = $self->eutil;
600 0 ▶ if ($self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_lazy) 0 0 0
601 0 $self->warn('rewind() not implemented yet when running in lazy mode');
602 0 return;
603 }
604 0 ▶ $arg ||= 'all';
Condition0%0/2
$arg ||= "all"
l!l
00
MC/DC0%0/1
$arg ||= "all"
$arg
Truth table0%0/2
A
A= $arg
Aresult
11
00
605 0 ▶ if (exists $VALID_ITERATORS{$arg}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $VALID_ITERATORS{$arg}) { } 0 0 0
elsif ($arg eq 'all') { } 0 0 0
606 0 delete $self->{'_'.$arg.'_it'};
607 } elsif ($arg eq 'all') {
608 0 for my $it (values %VALID_ITERATORS){
609 delete $self->{'_'.$it.'_it'} if
610 0 ▶ exists $self->{'_'.$it.'_it'};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$self{'_' . $it . '_it'} 0 0 0
611 0 map {$_->rewind('all')} $self->get_LinkSets;
612 0 map {$_->rewind('all')} $self->get_DocSums;
613 }
614 }
615 }
616  
617  
618 sub generate_iterator {
619 4 ▶ my ($self, $obj) = @_;
Subroutine generate_iterator: called CC=5 SCAR=24.5
Pod documented
620 4 ▶ if (!$obj) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $obj) { } 0 4 4
elsif (not exists $VALID_ITERATORS{$obj}) { } 0 4 4
621 0 $self->throw('Must provide object type to iterate');
622 } elsif (!exists $VALID_ITERATORS{$obj}) {
623 0 $self->throw("Unknown object type [$obj]");
624 }
625 4 my $cb = $self->callback;
626 4 ▶ if ($self->is_lazy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_lazy) { } 0 4 4
627 0 ▶ my $type = $self->eutil eq 'esummary' ? '_docsums' : '_linksets';
Branch: 1 branch
BranchTrueFalseTotal
$self->eutil eq 'esummary' ? : 0 0 0
628 0 $self->{$type} = [];
629 return sub {
630 0 ▶ if (!@{$self->{$type}}) {
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$self->{$type};}) 0 0 0
631 0 $self->parse_chunk; # fill the queue
632 }
633 0 ▶ while (my $obj = shift @{$self->{$type}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = shift @{$$self{$type};}) 0 0 0
634 0 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) { } 0 0 0
635 0 ▶ ($cb->($obj)) ? return $obj : next;
Branch: 1 branch
BranchTrueFalseTotal
&$cb($obj) ? : 0 0 0
636 } else {
637 0 return $obj;
638 }
639 }
640 0 undef;
641 }
642 0 } else {
643 4 my $loc = '_'.$VALID_ITERATORS{$obj};
644 4 my $index = $#{$self->{$loc}};
645 4 my $current = 0;
646 return sub {
647 4 ▶ while ($current <= $index) {
Subroutine __ANON__: called CC=4 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
if ($current <= $index) 2 2 4
648 2 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) { } 0 2 2
649 0 ▶ if (my $d = $cb->($self->{$loc}->[$current])) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $d = &$cb($self->{$loc}[$current])) { } 0 0 0
650 0 return $self->{$loc}->[$current++] }
651 else {
652 0 $current++;
653 0 next;
654 }
655 } else {
656 2 return $self->{$loc}->[$current++]
657 }
658 }
659 2 undef;
660 }
661 4 }
662 }
663  
664 }
665  
666  
667 19 sub callback {
668 4 ▶ my ($self, $cb) = @_;
Subroutine callback: called CC=4 SCAR=21.7
Pod documented
669 4 ▶ if ($cb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) 0 4 4
670 0 ▶ delete $self->{'_cb'} if ($cb eq 'reset');
Branch: 1 branch
BranchTrueFalseTotal
if $cb eq "reset" 0 0 0
671 0 ▶ return if ref $cb ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cb ne "CODE" 0 0 0
672 0 $self->{'_cb'} = $cb;
673 }
674 4 return $self->{'_cb'};
675 }
676  
677 # Object printing methods
678  
679 {
680 my $DEF_HANDLER = sub {
681 0 ▶ my $obj = shift;
Subroutine __ANON__: not called CC=1 SCAR=6.9
682 0 return $obj->to_string."\n";
683 19 };
684  
685 19 my %HANDLER = (
686 'DocSum' => 1,
687 'FieldInfo' => 1,
688 'LinkInfo' => 1,
689 'GlobalQuery' => 1,
690 'LinkSet' => 1,
691 'all' => 1,
692 );
693  
694 sub _print_handler {
695 0 ▶ my $self = shift;
Subroutine _print_handler: not called CC=14 SCAR=53.5
696 0 my ($file, $fh, $cb, $wrap, $type, $all) = $self->_rearrange([qw(FILE FH CB WRAP TYPE ALL)], @_);
697 0 ▶ $type ||= 'all';
Condition0%0/2
$type ||= "all"
l!l
00
MC/DC0%0/1
$type ||= "all"
$type
Truth table0%0/2
A
A= $type
Aresult
11
00
698  
699 # default formatting delegates to_string
700 0 ▶ if (!$cb) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $cb) { } 0 0 0
701 $self->throw("Type $type not registered with print handler, exiting...")
702 0 ▶ if !exists($HANDLER{$type});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HANDLER{$type} 0 0 0
703 0 $cb = $DEF_HANDLER;
704 } else {
705 0 ▶ $self->throw("Callback must be a code reference") if ref $cb ne 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $cb ne "CODE" 0 0 0
706 }
707  
708 0 ▶ $file ||= $fh;
Condition0%0/3
$file ||= $fh
l!l&&r!l&&!r
000
MC/DC0%0/2
$file ||= $fh
$file $fh
Truth table0%0/3
A ||= B
A= $fileB= $fh
ABresult
1X1
011
000
709 0 ▶ $self->throw("Have defined both file and filehandle; only use one!") if $file && $fh;
Branch: 1 branch
BranchTrueFalseTotal
if $file and $fh 0 0 0
Condition0%0/3
$file and $fh
!ll&&!rl&&r
000
MC/DC0%0/2
$file and $fh
$file $fh
Truth table0%0/3
A and B
A= $fileB= $fh
ABresult
0X0
100
111
710 0 ▶ my $io = ($file) ? Bio::Root::IO->new(-input => $file, -flush => 1) :
Branch: 1 branch
BranchTrueFalseTotal
$file ? : 0 0 0
711 Bio::Root::IO->new(-flush => 1); # defaults to STDOUT
712  
713 0 ▶ if ($type eq 'all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'all') { } 0 0 0
714 0 my $string = $cb->($self);
715 0 ▶ $io->_print($string) if $string;
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
716 } else {
717 # set up iterator
718 0 my $it = "next_$type";
719 0 ▶ $self->throw("Unknown iterator method $it") unless $self->can($it);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can($it) 0 0 0
720 0 ▶ while (my $obj = $self->$it) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $self->$it) 0 0 0
721 0 my $string = $cb->($obj);
722 0 ▶ $io->_print($string) if $string;
Branch: 1 branch
BranchTrueFalseTotal
if $string 0 0 0
723 }
724 }
725 0 $io->close;
726 }
727 }
728  
729 # Private methods
730  
731 19 sub _seekable {
732 0 ▶ return shift->{'_seekable'}
Subroutine _seekable: not called CC=1 SCAR=6.9
733 }
734  
735 # fixes odd bad XML issue espell data (still present 6-24-07)
736  
737 sub _fix_espell {
738 1 ▶ my ($self, $response) = @_;
Subroutine _fix_espell: called CC=5 SCAR=19.1
739 1 my $temp;
740 1 my $type = ref($response);
741 1 ▶ if ($type eq 'GLOB') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'GLOB') { } 1 0 1
elsif ($type eq 'HTTP::Response') { } 0 0 0
742 1 $temp .= $_ for <$response>;
743 } elsif ($type eq 'HTTP::Response') {
744 0 $temp = $response->content;
745 } else {
746 0 $self->throw("Unrecognized ref type $type");
747 }
748 1 ▶ if ($temp =~ m{^<html>}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($temp =~ /^<html>/) 0 1 1
749 0 $self->throw("NCBI espell nonrecoverable error: HTML content returned")
750 }
751 1 $temp =~ s{<ERROR>(.*?)<ERROR>}{<ERROR>$1</ERROR>};
752 1 return $temp;
753 }
754  
755 sub _load_eutil_module {
756 22 ▶ my ($self, $class) = @_;
Subroutine _load_eutil_module: called CC=2 SCAR=7.1
757 22 my $ok;
758 22 my $module = "Bio::Tools::EUtilities::" . $class;
759  
760 22 eval {
761 22 $ok = $self->_load_module($module);
762 };
763 22 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 22 22
764 0 print STDERR <<END;
765 $self: data module $module cannot be found
766 Exception $@
767 For more information about the EUtilities system please see the EUtilities docs.
768 END
769 ;
770 }
771 22 return $ok;
772 }
773  
774 19 1;
775  
776 __END__
« Tools/EUtilities/Query.pm ↑ Summary Tools/EUtilities/EUtilParameters.pm »