Bio/Root/HTTPget.pm

filter: Statementstmt 51.3% 77 / 150 Branchbran 26.6% 24 / 90 Conditioncond 20.0% 17 / 85 MC/DCmcdc 0.0% 0 / 48 Subroutinesub 75.0% 9 / 12 Podpod 100% 5 / 5 totaltotal 33.8% 132 / 390 CC 76 SCAR 47.3
CC
76
Cov
36%
getFH
380.0
get
59.1
_encode_base64
56.0
CRAP 113.5
« Bio/SeqFeature/Tools/TypeMapper.pm ↑ Summary Bio/SimpleAlign.pm »
1 #
2 # BioPerl module for fallback HTTP get operations.
3 #
4 # Module is proxy-aware
5 #
6 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 #
8 # Cared for by Chris Dagdigian <dag@sonsorol.org>
9 # but all of the good stuff was written by
10 # Lincoln Stein.
11 #
12 # You may distribute this module under the same terms as perl itself
13  
14 # POD documentation - main docs before the code
15  
16 =head1 NAME
17  
18 Bio::Root::HTTPget - module for fallback HTTP get operations when
19 LWP:: is unavailable
20  
21 =head1 SYNOPSIS
22  
23 use Bio::Root::HTTPget;
24 my $web = Bio::Root::HTTPget->new();
25  
26 my $response = $web->get('http://localhost');
27 $response = $web->get('http://localhost/images');
28  
29 $response = eval { $web->get('http://fred:secret@localhost/ladies_only/')
30 } or warn $@;
31  
32 $response = eval { $web->get('http://jeff:secret@localhost/ladies_only/')
33 } or warn $@;
34  
35 $response = $web->get('http://localhost/images/navauthors.gif');
36 $response = $web->get(-url=>'http://www.google.com',
37 -proxy=>'http://www.modperl.com');
38  
39 =head1 DESCRIPTION
40  
41 This is basically an last-chance module for doing network HTTP get
42 requests in situations where more advanced external CPAN modules such
43 as LWP:: are not installed.
44  
45 The particular reason this module was developed was so that the Open
46 Bio Database Access code can fallback to fetching the default registry
47 files from http://open-bio.org/registry/ without having to depend on
48 external dependencies like Bundle::LWP for network HTTP access.
49  
50 The core of this module was written by Lincoln Stein. It can handle proxies
51 and HTTP-based proxy authentication.
52  
53 =head1 FEEDBACK
54  
55 =head2 Mailing Lists
56  
57 User feedback is an integral part of the evolution of this
58 and other Bioperl modules. Send your comments and suggestions preferably
59 to one of the Bioperl mailing lists.
60 Your participation is much appreciated.
61  
62 bioperl-l@bioperl.org - General discussion
63 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
64  
65 =head2 Reporting Bugs
66  
67 Report bugs to the Bioperl bug tracking system to help us keep track
68 the bugs and their resolution. Bug reports can be submitted via the
69 web:
70  
71 https://github.com/bioperl/bioperl-live/issues
72  
73 =head1 AUTHOR - Lincoln Stein
74  
75 # Please direct questions and support issues to I<bioperl-l@bioperl.org>
76  
77 Cared for by Chris Dagdigian <dag@sonsorol.org>
78  
79 =head1 APPENDIX
80  
81 The rest of the documentation details each of the object
82 methods. Internal methods are usually preceded with a _
83  
84 =cut
85  
86  
87 # Let the code begin...
88  
89 package Bio::Root::HTTPget;
90 4 $Bio::Root::HTTPget::VERSION = '1.7.8';
91 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
92 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 4 ▶use IO::Socket qw(:DEFAULT :crlf);
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 4 ▶use base qw(Bio::Root::Root);
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 {
98 # default attributes, in case used as a class/sub call
99 4 my %attributes;
100  
101 =head2 get
102  
103 Title : get
104 Usage : my $resp = get(-url => $url);
105 Function:
106 Returns : string
107 Args : -url => URL to HTTPGet
108 -proxy => proxy to use
109 -user => username for proxy or authentication
110 -pass => password for proxy or authentication
111 -timeout => timeout
112  
113 =cut
114  
115 1 ▶sub get {
Subroutine get: called CC=23 SCAR=40.8
Pod documented
116 1 my $self;
117 1 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 1 0 1
Condition33%2/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
001
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
100
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table25%1/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
118 1 $self = shift;
119 }
120
121 1 my ($url,$proxy,$timeout,$auth_user,$auth_pass) =
122 __PACKAGE__->_rearrange([qw(URL PROXY TIMEOUT USER PASS)],@_);
123 1 ▶ my $dest = $proxy || $url;
Condition33%1/3
$proxy || $url
l!l&&r!l&&!r
010
MC/DC0%0/2
$proxy || $url
$proxy $url
Truth table33%1/3
A || B
A= $proxyB= $url
ABresult
1X1
011
000
124  
125 1 ▶ my ($host,$port,$path,$user,$pass)
Branch: 1 branch
BranchTrueFalseTotal
() = _http_parse_url($dest) or __PACKAGE__->throw("invalid URL $url") 1 0 1
126 = _http_parse_url($dest) or __PACKAGE__->throw("invalid URL $url");
127 1 ▶ $auth_user ||= $user;
Condition33%1/3
$auth_user ||= $user
l!l&&r!l&&!r
001
MC/DC0%0/2
$auth_user ||= $user
$auth_user $user
Truth table33%1/3
A ||= B
A= $auth_userB= $user
ABresult
1X1
011
000
128 1 ▶ $auth_pass ||= $pass;
Condition33%1/3
$auth_pass ||= $pass
l!l&&r!l&&!r
001
MC/DC0%0/2
$auth_pass ||= $pass
$auth_pass $pass
Truth table33%1/3
A ||= B
A= $auth_passB= $pass
ABresult
1X1
011
000
129 1 ▶ if ($self) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) 1 0 1
130 1 ▶ unless ($proxy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($proxy) 1 0 1
131 1 $proxy = $self->proxy;
132 }
133 1 ▶ unless ($auth_user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($auth_user) 1 0 1
134 1 ($auth_user, $auth_pass) = $self->authentication;
135 }
136 }
137 1 ▶ $path = $url if $proxy;
Branch: 1 branch
BranchTrueFalseTotal
if $proxy 0 1 1
138
139 # set up the connection
140 1 ▶ my $socket = _http_connect($host,$port) or __PACKAGE__->throw("can't connect: $@");
Branch: 1 branch
BranchTrueFalseTotal
my $socket = _http_connect($host, $port) or __PACKAGE__->throw("can't connect: $@") 1 0 1
141  
142 # the request
143 1 print $socket "GET $path HTTP/1.0$CRLF";
144 1 print $socket "User-Agent: Bioperl fallback fetcher/1.0$CRLF";
145 # Support virtual hosts
146 1 print $socket "HOST: $host$CRLF";
147  
148 1 ▶ if ($auth_user && $auth_pass) { # authentication information
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_user and $auth_pass) 0 1 1
Condition33%1/3
$auth_user and $auth_pass
!ll&&!rl&&r
100
MC/DC0%0/2
$auth_user and $auth_pass
$auth_user $auth_pass
Truth table33%1/3
A and B
A= $auth_userB= $auth_pass
ABresult
0X0
100
111
149 0 my $token = _encode_base64("$auth_user:$auth_pass");
150 0 print $socket "Authorization: Basic $token$CRLF";
151 }
152 1 print $socket "$CRLF";
153  
154 # read the response
155 1 my $response;
156 {
157 1 local $/ = "$CRLF$CRLF";
158 1 $response = <$socket>;
159 }
160  
161 1 my ($status_line,@other_lines) = split $CRLF,$response;
162 1 ▶ my ($stat_code,$stat_msg) = $status_line =~ m!^HTTP/1\.[01] (\d+) (.+)!
Branch: 1 branch
BranchTrueFalseTotal
() = $status_line =~ m[^HTTP/1\.[01] (\d+) (.+)] or __PACKAGE__->throw("invalid response from web server: got $response") 1 0 1
163 or __PACKAGE__->throw("invalid response from web server: got $response");
164  
165 1 my %headers = map {/^(\S+): (.+)/} @other_lines;
166 1 ▶ if ($stat_code == 302 || $stat_code == 301) { # redirect
Branch: 3 branches
BranchTrueFalseTotal
if ($stat_code == 302 or $stat_code == 301) { } 0 1 1
elsif ($stat_code == 401) { } 0 1 1
elsif ($stat_code != 200) { } 0 1 1
Condition33%1/3
$stat_code == 302 or $stat_code == 301
l!l&&r!l&&!r
001
MC/DC0%0/2
$stat_code == 302 or $stat_code == 301
$stat_code == 302 $stat_code == 301
Truth table33%1/3
A or B
A= $stat_code == 302B= $stat_code == 301
ABresult
1X1
011
000
167 my $location = $headers{Location} or
168 0 ▶ __PACKAGE__->throw("invalid redirect: no Location header");
Branch: 1 branch
BranchTrueFalseTotal
my $location = $headers{"Location"} or __PACKAGE__->throw("invalid redirect: no Location header") 0 0 0
169 0 return get(-url => $location, -proxy => $proxy, -timeout => $timeout, -user => $auth_user, -pass => $auth_pass); # recursive call
170 }
171  
172 elsif ($stat_code == 401) { # auth required
173 0 my $auth_required = $headers{'WWW-Authenticate'};
174 0 ▶ $auth_required =~ /^Basic realm="([^\"]+)"/
Branch: 1 branch
BranchTrueFalseTotal
$auth_required =~ /^Basic realm="([^\"]+)"/ or __PACKAGE__->throw('server requires unknown type of' . " authentication: $auth_required") 0 0 0
175 or __PACKAGE__->throw("server requires unknown type of".
176 " authentication: $auth_required");
177 0 __PACKAGE__->throw("request failed: $status_line, realm = $1");
178 }
179  
180 elsif ($stat_code != 200) {
181 0 __PACKAGE__->throw("request failed: $status_line");
182 }
183  
184 1 $response = '';
185 1 while (1) {
186 44 my $bytes = read($socket,$response,2048,length $response);
187 44 ▶ last unless $bytes > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $bytes > 0 1 43 44
188 }
189  
190 1 $response;
191 }
192  
193 =head2 getFH
194  
195 Title : getFH
196 Usage :
197 Function:
198 Example :
199 Returns : string
200 Args :
201  
202 =cut
203  
204 0 ▶sub getFH {
Subroutine getFH: not called CC=19 SCAR=59.4
Pod documented
205 0 my $self;
206 0 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 0 0 0
Condition0%0/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
000
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table0%0/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
207 0 $self = shift;
208 }
209 0 my ($url,$proxy,$timeout,$auth_user,$auth_pass) =
210 __PACKAGE__->_rearrange([qw(URL PROXY TIMEOUT USER PASS)],@_);
211 0 ▶ my $dest = $proxy || $url;
Condition0%0/3
$proxy || $url
l!l&&r!l&&!r
000
MC/DC0%0/2
$proxy || $url
$proxy $url
Truth table0%0/3
A || B
A= $proxyB= $url
ABresult
1X1
011
000
212  
213 0 ▶ my ($host,$port,$path,$user,$pass)
Branch: 1 branch
BranchTrueFalseTotal
() = _http_parse_url($dest) or __PACKAGE__->throw("invalid URL $url") 0 0 0
214 = _http_parse_url($dest) or __PACKAGE__->throw("invalid URL $url");
215 0 ▶ $auth_user ||= $user;
Condition0%0/3
$auth_user ||= $user
l!l&&r!l&&!r
000
MC/DC0%0/2
$auth_user ||= $user
$auth_user $user
Truth table0%0/3
A ||= B
A= $auth_userB= $user
ABresult
1X1
011
000
216 0 ▶ $auth_pass ||= $pass;
Condition0%0/3
$auth_pass ||= $pass
l!l&&r!l&&!r
000
MC/DC0%0/2
$auth_pass ||= $pass
$auth_pass $pass
Truth table0%0/3
A ||= B
A= $auth_passB= $pass
ABresult
1X1
011
000
217 0 ▶ $path = $url if $proxy;
Branch: 1 branch
BranchTrueFalseTotal
if $proxy 0 0 0
218  
219 # set up the connection
220 0 ▶ my $socket = _http_connect($host,$port) or __PACKAGE__->throw("can't connect: $@");
Branch: 1 branch
BranchTrueFalseTotal
my $socket = _http_connect($host, $port) or __PACKAGE__->throw("can't connect: $@") 0 0 0
221  
222 # the request
223 0 print $socket "GET $path HTTP/1.0$CRLF";
224 0 print $socket "User-Agent: Bioperl fallback fetcher/1.0$CRLF";
225 # Support virtual hosts
226 0 print $socket "HOST: $host$CRLF";
227  
228 0 ▶ if ($auth_user && $auth_pass) { # authentication information
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_user and $auth_pass) 0 0 0
Condition0%0/3
$auth_user and $auth_pass
!ll&&!rl&&r
000
MC/DC0%0/2
$auth_user and $auth_pass
$auth_user $auth_pass
Truth table0%0/3
A and B
A= $auth_userB= $auth_pass
ABresult
0X0
100
111
229 0 my $token = _encode_base64("$auth_user:$auth_pass");
230 0 print $socket "Authorization: Basic $token$CRLF";
231 }
232 0 print $socket "$CRLF";
233  
234 # read the response
235 0 my $response;
236 {
237 0 local $/ = "$CRLF$CRLF";
238 0 $response = <$socket>;
239 }
240  
241 0 my ($status_line,@other_lines) = split $CRLF,$response;
242 0 ▶ my ($stat_code,$stat_msg) = $status_line =~ m!^HTTP/1\.[01] (\d+) (.+)!
Branch: 1 branch
BranchTrueFalseTotal
() = $status_line =~ m[^HTTP/1\.[01] (\d+) (.+)] or __PACKAGE__->throw("invalid response from web server: got $response") 0 0 0
243 or __PACKAGE__->throw("invalid response from web server: got $response");
244  
245 0 my %headers = map {/^(\S+): (.+)/} @other_lines;
246 0 ▶ if ($stat_code == 302 || $stat_code == 301) { # redirect
Branch: 3 branches
BranchTrueFalseTotal
if ($stat_code == 302 or $stat_code == 301) { } 0 0 0
elsif ($stat_code == 401) { } 0 0 0
elsif ($stat_code != 200) { } 0 0 0
Condition0%0/3
$stat_code == 302 or $stat_code == 301
l!l&&r!l&&!r
000
MC/DC0%0/2
$stat_code == 302 or $stat_code == 301
$stat_code == 302 $stat_code == 301
Truth table0%0/3
A or B
A= $stat_code == 302B= $stat_code == 301
ABresult
1X1
011
000
247 my $location = $headers{Location} or
248 0 ▶ __PACKAGE__->throw("invalid redirect: no Location header");
Branch: 1 branch
BranchTrueFalseTotal
my $location = $headers{"Location"} or __PACKAGE__->throw("invalid redirect: no Location header") 0 0 0
249 0 return getFH(-url => $location, -proxy => $proxy, -timeout => $timeout, -user => $auth_user, -pass => $auth_pass); # recursive call
250 }
251  
252 elsif ($stat_code == 401) { # auth required
253 0 my $auth_required = $headers{'WWW-Authenticate'};
254 0 ▶ $auth_required =~ /^Basic realm="([^\"]+)"/
Branch: 1 branch
BranchTrueFalseTotal
$auth_required =~ /^Basic realm="([^\"]+)"/ or __PACKAGE__->throw('server requires unknown type of ' . "authentication: $auth_required") 0 0 0
255 or __PACKAGE__->throw("server requires unknown type of ".
256 "authentication: $auth_required");
257 0 __PACKAGE__->throw("request failed: $status_line, realm = $1");
258 }
259  
260 elsif ($stat_code != 200) {
261 0 __PACKAGE__->throw("request failed: $status_line");
262 }
263  
264 # Now that we are reasonably sure the socket and request
265 # are OK we pass the socket back as a filehandle so it can
266 # be processed by the caller...
267  
268 0 $socket;
269  
270 }
271  
272  
273 =head2 _http_parse_url
274  
275 Title :
276 Usage :
277 Function:
278 Example :
279 Returns :
280 Args :
281  
282 =cut
283  
284 1 ▶sub _http_parse_url {
Subroutine _http_parse_url: called CC=7 SCAR=23.4
285 1 my $self;
286 1 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 0 1 1
Condition33%2/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
010
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
001
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table25%1/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
287 0 $self = shift;
288 }
289 1 my $url = shift;
290 1 ▶ my ($user,$pass,$hostent,$path) =
Branch: 1 branch
BranchTrueFalseTotal
() = $url =~ m[^http://(?:([^:]+):([^:]+)@)?([^/]+)(/?[^\#]*)] or return 1 0 1
291 $url =~ m!^http://(?:([^:]+):([^:]+)@)?([^/]+)(/?[^\#]*)! or return;
292 1 ▶ $path ||= '/';
Condition50%1/2
$path ||= "/"
l!l
10
MC/DC0%0/1
$path ||= "/"
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
293 1 my ($host,$port) = split(':',$hostent);
294 1 ▶ return ($host,$port||80,$path,$user,$pass);
Condition50%1/2
$port || 80
l!l
01
MC/DC0%0/1
$port || 80
$port
Truth table50%1/2
A
A= $port
Aresult
11
00
295 }
296  
297 =head2 _http_connect
298  
299 Title :
300 Usage :
301 Function:
302 Example :
303 Returns :
304 Args :
305  
306 =cut
307  
308 1 ▶sub _http_connect {
Subroutine _http_connect: called CC=1 SCAR=0.0
309 1 my ($host,$port,$timeout) = @_;
310 1 my $sock = IO::Socket::INET->new(Proto => 'tcp',
311 Type => SOCK_STREAM,
312 PeerHost => $host,
313 PeerPort => $port,
314 Timeout => $timeout,
315 );
316 1 $sock;
317 }
318  
319  
320 =head2 _encode_base64
321  
322 Title :
323 Usage :
324 Function:
325 Example :
326 Returns :
327 Args :
328  
329 =cut
330  
331 0 ▶sub _encode_base64 {
Subroutine _encode_base64: not called CC=7 SCAR=40.3
332 0 my $self;
333 0 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 0 0 0
Condition0%0/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
000
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table0%0/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
334 0 $self = shift;
335 }
336 0 my $res = "";
337 0 my $eol = $_[1];
338 0 ▶ $eol = "\n" unless defined $eol;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $eol 0 0 0
339 0 pos($_[0]) = 0; # ensure start at the beginning
340  
341 0 $res = join '', map( pack('u',$_)=~ /^.(\S*)/, ($_[0]=~/(.{1,45})/gs));
342  
343 0 $res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
344 # fix padding at the end
345 0 my $padding = (3 - length($_[0]) % 3) % 3;
346 0 ▶ $res =~ s/.{$padding}$/'=' x $padding/e if $padding;
Branch: 1 branch
BranchTrueFalseTotal
if $padding 0 0 0
347 # break encoded string into lines of no more than 76 characters each
348 0 ▶ if (length $eol) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $eol) 0 0 0
349 0 $res =~ s/(.{1,76})/$1$eol/g;
350 }
351 0 return $res;
352 }
353  
354  
355 =head2 proxy
356  
357 Title : proxy
358 Usage : $httpproxy = $db->proxy('http') or
359 $db->proxy(['http','ftp'], 'http://myproxy' )
360 Function: Get/Set a proxy for use of proxy. Defaults to environment variable
361 http_proxy if present.
362 Returns : a string indicating the proxy
363 Args : $protocol : string for the protocol to set/get
364 $proxyurl : url of the proxy to use for the specified protocol
365 $username : username (if proxy requires authentication)
366 $password : password (if proxy requires authentication)
367  
368 =cut
369  
370 1 ▶sub proxy {
Subroutine proxy: called CC=12 SCAR=36.2
Pod documented
371 1 my $self;
372 1 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 1 0 1
Condition33%2/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
001
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
100
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table25%1/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
373 1 $self = shift;
374 }
375 1 my ($protocol,$proxy,$username,$password) = @_;
376 1 ▶ my $atts = ref($self) ? $self : \%attributes;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 0 1
377 1 ▶ $protocol ||= 'http';
Condition50%1/2
$protocol ||= "http"
l!l
01
MC/DC0%0/1
$protocol ||= "http"
$protocol
Truth table50%1/2
A
A= $protocol
Aresult
11
00
378 1 ▶ if (!$proxy) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($proxy) 1 0 1
379 1 ▶ if (defined $ENV{http_proxy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ENV{"http_proxy"}) 0 1 1
380 0 $proxy = $ENV{http_proxy};
381 0 ▶ if ($proxy =~ /\@/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($proxy =~ /\@/) 0 0 0
382 0 ($username, $password, $proxy) = $proxy =~ m{http://(\S+):(\S+)\@(\S+)};
383 0 $proxy = 'http://'.$proxy;
384 }
385 }
386 }
387 1 ▶ if (defined $proxy) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $proxy) 0 1 1
388 # default to class method call
389 0 ▶ __PACKAGE__->authentication($username, $password)
Branch: 1 branch
BranchTrueFalseTotal
if $username and $password 0 0 0
Condition0%0/3
$username and $password
!ll&&!rl&&r
000
MC/DC0%0/2
$username and $password
$username $password
Truth table0%0/3
A and B
A= $usernameB= $password
ABresult
0X0
100
111
390 if ($username && $password);
391 0 $atts->{'_proxy'}->{$protocol} = $proxy;
392 }
393 1 return $atts->{'_proxy'}->{$protocol};
394 }
395  
396 =head2 clear_proxy
397  
398 Title : clear_proxy
399 Usage : my $old_prozy = $db->clear_proxy('http')
400 Function: Unsets (clears) the proxy for the protocol indicated
401 Returns : a string indicating the old proxy value
402 Args : $protocol : string for the protocol to clear
403  
404 =cut
405  
406 0 ▶sub clear_proxy {
Subroutine clear_proxy: not called CC=6 SCAR=37.4
Pod documented
407 0 my $self;
408 0 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 0 0 0
Condition0%0/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
000
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table0%0/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
409 0 $self = shift;
410 }
411 0 my ($protocol) = @_;
412 0 ▶ my $atts = ref($self) ? $self : \%attributes;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
413 0 ▶ $protocol ||= 'http';
Condition0%0/2
$protocol ||= "http"
l!l
00
MC/DC0%0/1
$protocol ||= "http"
$protocol
Truth table0%0/2
A
A= $protocol
Aresult
11
00
414 0 delete $atts->{'_proxy'}->{$protocol};
415 }
416  
417 =head2 authentication
418  
419 Title : authentication
420 Usage : $db->authentication($user,$pass)
421 Function: Get/Set authentication credentials
422 Returns : Array of user/pass
423 Args : Array or user/pass
424  
425  
426 =cut
427  
428 1 ▶sub authentication {
Subroutine authentication: called CC=8 SCAR=27.7
Pod documented
429 1 my $self;
430 1 ▶ if($_[0] && (ref($_[0]) or $_[0] =~ /^Bio::/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] and ref $_[0] || $_[0] =~ /^Bio::/) 1 0 1
Condition33%2/6
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
!ll&&!rl&&r
001
ref $_[0] or $_[0] =~ /^Bio::/
l!l&&r!l&&!r
100
MC/DC0%0/3
$_[0] and ref $_[0] || $_[0] =~ /^Bio::/
$_[0] ref $_[0] $_[0] =~ /^Bio::/
Truth table25%1/4
A and B or C
A= $_[0]B= ref $_[0]C= $_[0] =~ /^Bio::/
ABCresult
0XX0
1000
11X1
1011
431 1 $self = shift;
432 }
433 1 ▶ my $atts = ref($self) ? $self : \%attributes;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 1 0 1
434 1 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 1 1
435 0 my ($u,$p) = @_;
436 0 ▶ my $atts = ref($self) ? $self : \%attributes;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
437
438 0 $atts->{'_authentication'} = [ $u,$p];
439 }
440 1 ▶ return @{$atts->{'_authentication'} || []};
Condition50%1/2
$atts->{'_authentication'} || []
l!l
01
MC/DC0%0/1
$atts->{'_authentication'} || []
$atts->{'_authentication'}
Truth table50%1/2
A
A= $atts->{'_authentication'}
Aresult
11
00
441 }
442  
443 }
444  
445 4 1;
« Bio/SeqFeature/Tools/TypeMapper.pm ↑ Summary Bio/SimpleAlign.pm »