BioPerl

 view release on metacpan or  search on metacpan

Bio/DB/Query/WebQuery.pm  view on Meta::CPAN

  if ($ids) {
    $query = $self->_generate_id_string($ids);
  }
  $self->query($query);
  $verbose && $self->verbose($verbose);

  my $ua = LWP::UserAgent->new(env_proxy => 1);
  $ua->agent(ref($self) ."/".($Bio::DB::Query::WebQuery::VERSION || '0.1'));
  $self->ua($ua);
  $self->{'_authentication'} = [];
  $self;
}

=head2 ua

 Title   : ua
 Usage   : my $ua = $self->ua or 
           $self->ua($ua)
 Function: Get/Set a LWP::UserAgent for use
 Returns : reference to LWP::UserAgent Object
 Args    : $ua - must be a LWP::UserAgent

=cut

sub ua {
   my ($self, $ua) = @_;
   my $d = $self->{'_ua'};
   if( defined $ua && $ua->isa("LWP::UserAgent") ) {
      $self->{'_ua'} = $ua;
   }
   $d;
}

=head2 proxy

 Title   : proxy
 Usage   : $httpproxy = $db->proxy('http')  or 
           $db->proxy(['http','ftp'], 'http://myproxy' )
 Function: Get/Set a proxy for use of proxy
 Returns : a string indicating the proxy
 Args    : $protocol : an array ref of the protocol(s) to set/get
           $proxyurl : url of the proxy to use for the specified protocol
           $username : username (if proxy requires authentication)
           $password : password (if proxy requires authentication)

=cut

sub proxy {
    my ($self,$protocol,$proxy,$username,$password) = @_;
    return undef if ( !defined $self->ua || !defined $protocol 
		      || !defined $proxy );
    $self->authentication($username, $password) 	
	if ($username && $password);
    return $self->ua->proxy($protocol,$proxy);
}

=head2 authentication

 Title   : authentication
 Usage   : $db->authentication($user,$pass)
 Function: Get/Set authentication credentials
 Returns : Array of user/pass 
 Args    : Array or user/pass


=cut

sub authentication{
   my ($self,$u,$p) = @_;

   if( defined $u && defined $p ) {
       $self->{'_authentication'} = [ $u,$p];
   }
   return @{$self->{'_authentication'}};
}

=head2 ids

 Title   : ids
 Usage   : @ids = $db->ids([@ids])
 Function: get/set matching ids
 Returns : array of sequence ids
 Args    : (optional) array ref with new set of ids

=cut

sub ids     {
  my $self = shift;
  if (@_) {
    my $d = $self->{'_ids'};
    my $arg = shift;
    $self->{'_ids'} = ref $arg ? $arg : [$arg];
    return $d ? @$d : ();
  } else {
    $self->_fetch_ids;
    return @{$self->{'_ids'} || []};
  }
}

=head2 query

 Title   : query
 Usage   : $query = $db->query([$query])
 Function: get/set query string
 Returns : string
 Args    : (optional) new query string

=cut

sub query   {
  my $self = shift;
  my $d    = $self->{'_query'};
  $self->{'_query'} = shift if @_;
  $d;
}

=head2 _fetch_ids

 Title   : _fetch_ids
 Usage   : @ids = $db->_fetch_ids
 Function: run query, get ids



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