File Coverage

blib/lib/Bio/GMOD/Adaptor.pm
Criterion Covered Total %
statement 10 12 83.3
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 14 16 87.5


line stmt bran cond sub pod time code
1             package Bio::GMOD::Adaptor;
2              
3 2     2   67877 use strict;
  2         3  
  2         86  
4 2     2   11 use vars qw/@ISA/;
  2         4  
  2         305  
5 2     2   3511 use LWP::UserAgent;
  2         177884  
  2         121  
6 2     2   1789 use Bio::GMOD::Util::CheckVersions;
  0            
  0            
7             use Bio::GMOD::Util::Rearrange;
8              
9             @ISA = qw/
10             Bio::GMOD
11             Bio::GMOD::Util::CheckVersions
12             /;
13             # Bio::GMOD::StandardURLs
14              
15             sub new {
16             my ($self,$overrides) = @_;
17             my $adaptor = bless {},$self;
18             eval {"require $self"} or $self->logit(-msg => "Couldn't require the $self package: $!",-die => 1);
19              
20             # Is a defaults script available?
21             # This should be converted to XML
22             if ($adaptor->defaults_cgi) {
23             my $ua = LWP::UserAgent->new();
24             my $version = $self->biogmod_version;
25             $ua->agent("Bio::GMOD.pm/$version");
26             my $request = HTTP::Request->new('GET',$adaptor->defaults_cgi);
27             my $response = $ua->request($request);
28              
29             if ($response->is_success) {
30             # Parse out the content and store the defaults in the object
31             my $content = $response->content;
32             my @lines = split("\n",$content);
33             foreach (@lines) {
34             next if /^\#/; # ignore comments
35             my ($key,$val) = split("=");
36             $adaptor->{defaults}->{lc($key)} = $val;
37             }
38             $adaptor->{status} = "SUCCESS";
39             } else {
40             # Couldn't fetch the defaults script - maybe working offline
41              
42             # Until fully tested, let's require that you be online.
43             # WiMax is coming anyways, right ;)
44              
45             $adaptor->logit(-msg => "Couldn't fetch defaults script:\n\t"
46             . $response->status_line .
47             "\n\tYou may be working offline. Defaults will be populated from adaptor object",
48             # -die=>1
49             );
50             }
51             }
52              
53             # Override some of the defaults if requested
54             foreach my $key (keys %$overrides) {
55             my $value = $overrides->{$key};
56             next unless $value;
57             $adaptor->{defaults}->{lc($key)} = $value;
58             }
59              
60             my @defaults = $self->defaults;
61              
62             # Finally, fetch the values hardcoded in the Adaptor::*
63             foreach my $key (@defaults) {
64             next if defined $adaptor->{defaults}->{lc($key)};
65             $key = lc ($key);
66             my $hard_coded = $adaptor->$key;
67             next unless $hard_coded;
68             $adaptor->{defaults}->{$key} = $hard_coded;
69             }
70             return $adaptor;
71             }
72              
73             # Generically accept parameters, loading them into the adaptor object.
74             sub parse_params {
75             my ($self,@p) = @_;
76             return unless @p;
77             my %params = @p;
78             foreach my $key (keys %params) {
79             my $value = $params{$key};
80             # strip of leading hypens.
81             # Some may have two coming from @ARGV and command line
82             $key =~ s/^\-\-{0,1}//;
83             # next if defined $self->{defaults}->{lc($key)};
84             $self->{defaults}->{lc($key)} = $value;
85             }
86             }
87              
88              
89             __END__