2 # BioPerl module for Bio::WebAgent
4 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 # Cared for by Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
7 # For copyright and disclaimer see below.
10 # POD documentation - main docs before the code
14 Bio::WebAgent - A base class for Web (any protocol) access
18 # This is a abstract superclass for bioperl modules accessing web
19 # resources - normally you do not instantiate it but one of its
24 This abstract superclass is a subclass of L<LWP::UserAgent> which
25 allows protocol independent access of remote locations over
28 It takes care of error handling, proxies and various net protocols.
29 BioPerl classes accessing the net should inherit from it. For details,
30 see L<LWP::UserAgent>.
32 The interface is still evolving. For now, two public methods have been
33 copied from Bio::DB::WebDBSeqI: delay() and delay_policy. These are
34 used to prevent overwhelming the server by rapidly repeated . Ideally
35 there should be a common abstract superclass with these. See L<delay>.
40 L<Bio::DB::WebDBSeqI>,
46 User feedback is an integral part of the evolution of this and other
47 Bioperl modules. Send your comments and suggestions preferably to
48 the Bioperl mailing list. Your participation is much appreciated.
50 bioperl-l@bioperl.org - General discussion
51 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
55 Please direct usage questions or support issues to the mailing list:
57 I<bioperl-l@bioperl.org>
59 rather than to the module maintainer directly. Many experienced and
60 reponsive experts will be able look at the problem and quickly
61 address it. Please include a thorough description of the problem
62 with code and data examples if at all possible.
66 Report bugs to the Bioperl bug tracking system to help us keep track
67 of the bugs and their resolution. Bug reports can be submitted via the
70 https://github.com/bioperl/bioperl-live/issues
74 Heikki Lehvaslaiho, heikki-at-bioperl-dot-org
78 Copyright (c) 2003, Heikki Lehvaslaiho and EMBL-EBI.
81 This module is free software; you can redistribute it and/or modify
82 it under the same terms as Perl itself.
86 This software is provided "as is" without warranty of any kind.
90 The rest of the documentation details each of the object
91 methods. Internal methods are usually preceded with a _
96 # Let the code begin...
98 package Bio
::WebAgent
;
100 use vars
qw($LAST_INVOCATION_TIME);
103 use base qw(LWP::UserAgent Bio::Root::Root);
109 # We make env_proxy the default here, but it can be
110 # over-ridden by $self->env_proxy later,
111 # or by new(env_proxy=>0) at constructor time
113 my $self = $class->SUPER::new
(env_proxy
=> 1);
119 $self->can($key) || next;
123 return $self; # success - we hope!
128 # -----------------------------------------------------------------------------
133 Returns : URL to reach out to Net
139 my ($self,$value) = @_;
140 if( defined $value) {
141 $self->{'_url'} = $value;
143 return $self->{'_url'};
150 Usage : $secs = $self->delay([$secs])
151 Function: get/set number of seconds to delay between fetches
152 Returns : number of seconds to delay
155 NOTE: the default is to use the value specified by delay_policy().
156 This can be overridden by calling this method, or by passing the
157 -delay argument to new().
162 my ($self, $value) = @_;
164 $self->throw("Need a positive integer, not [$value]")
166 $self->{'_delay'} = int $value;
168 return $self->{'_delay'} || $self->delay_policy;
174 Usage : $secs = $self->delay_policy
175 Function: return number of seconds to delay between calls to remote db
176 Returns : number of seconds to delay
179 NOTE: The default delay policy is 3s. Override in subclasses to
180 implement other delays. The timer has only second resolution, so the delay
181 will actually be +/- 1s.
195 Function: sleep for a number of seconds indicated by the delay policy
199 NOTE: This method keeps track of the last time it was called and only
200 imposes a sleep if it was called more recently than the delay_policy()
207 $LAST_INVOCATION_TIME ||= 0;
208 if (time - $LAST_INVOCATION_TIME < $self->delay) {
209 my $delay = $self->delay - (time - $LAST_INVOCATION_TIME);
210 $self->debug("sleeping for $delay seconds\n");
213 $LAST_INVOCATION_TIME = time;