BioPerl

 view release on metacpan or  search on metacpan

Bio/WebAgent.pm  view on Meta::CPAN

		$self->$key($value);
	}

	return $self; # success - we hope!

}


# -----------------------------------------------------------------------------

=head2 url

 Usage   : $agent->url
 Returns : URL to reach out to Net
 Args    : string

=cut

sub url { 
   my ($self,$value) = @_;
   if( defined $value) {
		$self->{'_url'} = $value;
   }
   return $self->{'_url'};
}


=head2 delay

 Title   : delay
 Usage   : $secs = $self->delay([$secs])
 Function: get/set number of seconds to delay between fetches
 Returns : number of seconds to delay
 Args    : new value

NOTE: the default is to use the value specified by delay_policy().
This can be overridden by calling this method, or by passing the
-delay argument to new().

=cut

sub delay {
   my ($self, $value) = @_;
   if ($value) {
       $self->throw("Need a positive integer, not [$value]")
           unless $value >= 0;
       $self->{'_delay'} = int $value;
   }
   return $self->{'_delay'} || $self->delay_policy;
}

=head2 delay_policy

 Title   : delay_policy
 Usage   : $secs = $self->delay_policy
 Function: return number of seconds to delay between calls to remote db
 Returns : number of seconds to delay
 Args    : none

NOTE: The default delay policy is 3s.  Override in subclasses to
implement other delays.  The timer has only second resolution, so the delay
will actually be +/- 1s.

=cut

sub delay_policy {
   my $self = shift;
   return 3;
}


=head2 sleep

 Title   : sleep
 Usage   : $self->sleep
 Function: sleep for a number of seconds indicated by the delay policy
 Returns : none
 Args    : none

NOTE: This method keeps track of the last time it was called and only
imposes a sleep if it was called more recently than the delay_policy()
allows.

=cut

sub sleep {
   my $self = shift;
   $LAST_INVOCATION_TIME ||=  0;
   if (time - $LAST_INVOCATION_TIME < $self->delay) {
      my $delay = $self->delay - (time - $LAST_INVOCATION_TIME);
      $self->debug("sleeping for $delay seconds\n");
      sleep $delay;
   }
   $LAST_INVOCATION_TIME = time;
}

1;

__END__



( run in 1.376 second using v1.01-cache-2.11-cpan-39bf76dae61 )