File Coverage

blib/lib/Bio/GMOD/Util/CheckVersions.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 18 20 90.0


line stmt bran cond sub pod time code
1             package Bio::GMOD::Util::CheckVersions;
2 8     8   52469 use strict;
  8         20  
  8         355  
3              
4 8     8   14300 use Bio::GMOD;
  8         25  
  8         217  
5 8     8   50 use Bio::GMOD::Util::Rearrange;
  8         15  
  8         535  
6 8     8   10485 use LWP::UserAgent;
  8         468921  
  8         285  
7 8     8   4127 use XML::Simple;
  0            
  0            
8              
9             use vars qw/@ISA/;
10              
11             @ISA = qw/Bio::GMOD/;
12              
13             sub live_version {
14             my ($self,@p) = @_;
15             my $adaptor = $self->adaptor;
16             my $response = $self->_check_version($adaptor->live_url,$adaptor->version_live);
17             # Save the current live version
18             $adaptor->{defaults}->{live_version} = $response->{version};
19             return (wantarray ? %$response : $response->{version});
20             }
21              
22              
23             sub development_version {
24             my ($self,@p) = @_;
25             my $adaptor = $self->adaptor;
26             unless ($adaptor->development_url) {
27             return (wantarray ? ( site => 'no development server specified' ) : 'no development server specified');
28             }
29             my $response = $self->_check_version($adaptor->development_url,$adaptor->version_dev);
30             # Save the current dev version
31             $adaptor->{defaults}->{dev_version} = $response->{version};
32             return (wantarray ? %$response : $response->{version});
33             }
34              
35             sub mirror_version {
36             my ($self,@p) = @_;
37             my ($site,$cgi) = rearrange([qw/SITE CGI/],@p);
38             my $adaptor = $self->adaptor;
39             $site =~ s/\/$//;
40             my $response = $self->_check_version($site,"$site/$cgi");
41             return (wantarray ? %$response : $response->{version});
42             }
43              
44             # Local version should be supplied by subclass
45             # We not yet have instantiated a CheckVersions::* object
46             # if we have come from, say, Update::*
47             # Instantiate now, and pass the parent class for the adaptor
48             # Exceptionally poor design flaw.
49             sub local_version {
50             my $self = shift;
51             my $mod = $self->mod;
52             my $subclass = "Bio::GMOD::Util::CheckVersions::$mod";
53             eval "require $subclass" or $self->logit(-msg=>"Could not subclass $subclass: $!",-die=>1);
54             my %response = $subclass->local_version(-parent => $self);
55             return (wantarray ? %response : $response{version});
56             }
57              
58             # Placeholder - not sure if I am going to implement this
59             #sub package_version {
60             #}
61              
62             # Read the contents of a provided symlink (or path) to parse out a version
63             # Returning the full path the symlink points at, the installed version
64             # and its modtime
65             sub read_symlink {
66             my ($self,$path) = @_;
67             my $realdir = -l $path ? readlink $path : $path;
68             my ($root) = $path =~ /(.*\/).*/;
69             my $full_path = $root . "/$realdir";
70             my @temp = stat($full_path);
71             my $modtime = localtime($temp[9]);
72             return ($realdir,$modtime);
73             }
74              
75              
76              
77              
78             ##################################
79             # PRIVATE METHODS
80             ##################################
81             sub _check_version {
82             my ($self,$site,$url) = @_;
83             # Version script holds a simple cgi that dumps out the
84             # title, release date, and version of the database
85             $url ||= $site;
86             my $version = $self->biogmod_version;
87             my $ua = LWP::UserAgent->new();
88             $ua->agent("Bio::GMOD::Util::CheckVersions/$version");
89             my $request = HTTP::Request->new('GET',$url);
90             my $response = $ua->request($request);
91             my %response;
92             if ($response->is_success) {
93             # Parse out the content
94             my $content = $response->content;
95             my $parsed = XMLin($content);
96             foreach (keys %{$parsed}) {
97             $response{$_} = $parsed->{$_};
98             }
99             $response{status} = "SUCCESS";
100             } else {
101             $response{error} = "FAILURE: Couldn't check version: " . $response->status_line;
102             }
103             $response{url} = $site;
104             return \%response;
105             }
106              
107              
108              
109             __END__