blib/lib/Bio/Installer/Generic.pm untested

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 41 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 175 CC 10 SCAR 15.9
CC
10
Cov
0%
origin_download_dir
6.0
destination_download_dir
6.0
destination_install_dir
6.0
CRAP 4.9
1 # BioPerl module for Bio::Installer::Generic
2 #
3 # Please direct questions and support issues to <bioperl-l@bioperl.org>
4 #
5 # Cared for by Albert Vilella
6 #
7 # Copyright Albert Vilella
8 #
9 # You may distribute this module under the same terms as perl itself
10  
11 # POD documentation - main docs before the code
12  
13 =head1 NAME
14  
15 Bio::Installer::Generic - DESCRIPTION of Object
16  
17 =head1 SYNOPSIS
18  
19 Give standard usage here
20  
21 =head1 DESCRIPTION
22  
23 Describe the object here
24  
25 =head1 FEEDBACK
26  
27 =head2 Mailing Lists
28  
29 User feedback is an integral part of the evolution of this and other
30 Bioperl modules. Send your comments and suggestions preferably to
31 the Bioperl mailing list. Your participation is much appreciated.
32  
33 bioperl-l@bioperl.org - General discussion
34 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
35  
36 =head2 Support
37  
38 Please direct usage questions or support issues to the mailing list:
39  
40 I<bioperl-l@bioperl.org>
41  
42 rather than to the module maintainer directly. Many experienced and
43 reponsive experts will be able look at the problem and quickly
44 address it. Please include a thorough description of the problem
45 with code and data examples if at all possible.
46  
47 =head2 Reporting Bugs
48  
49 Report bugs to the Bioperl bug tracking system to help us keep track
50 of the bugs and their resolution. Bug reports can be submitted via
51 the web:
52  
53 http://redmine.open-bio.org/projects/bioperl/
54  
55 =head1 AUTHOR - Albert Vilella
56  
57 Email avilella-AT-gmail-DOT-com
58  
59 Describe contact details here
60  
61 =head1 CONTRIBUTORS
62  
63 Additional contributors names and emails here
64  
65 =head1 APPENDIX
66  
67 The rest of the documentation details each of the object methods.
68 Internal methods are usually preceded with a _
69  
70 =cut
71  
72  
73 # Let the code begin...
74  
75  
76 package Bio::Installer::Generic;
77 use vars qw(@ISA);
78 use strict;
79  
80 # Object preamble - inherits from Bio::Root::Root
81  
82 use Bio::Root::Root;
83 # Download file
84 use LWP;
85 use HTTP::Request::Common;
86  
87 @ISA = qw(Bio::Root::Root );
88  
89  
90 =head2 new
91  
92 Title : new
93 Usage : my $obj = new Generic();
94 Function: Builds a new Generic object
95 Returns : an instance of Generic
96 Args : -origin_download_dir => from where is going to be downloaded
97 -destination_download_dir => where is going to be saved
98 -destination_install_dir => where is going to be installed
99 -package_name => name of the package to be downloaded
100 -directory_name => name of the directory once has been decompressed
101  
102  
103 =cut
104  
105 sub new {
106 my($class,@args) = @_;
107  
108 my $self = $class->SUPER::new(@args);
109  
110 my ($origin_download_dir,
111 $destination_download_dir,
112 $destination_install_dir,
113 $package_name,
114 $directory_name) =
115 $self->_rearrange( [qw(ORIGIN_DOWNLOAD_DIR
116 DESTINATION_DOWNLOAD_DIR
117 DESTINATION_INSTALL_DIR
118 PACKAGE_NAME
119 DIRECTORY_NAME)],
120 @args);
121 defined $origin_download_dir && $self->origin_download_dir($origin_download_dir);
122 defined $destination_download_dir && $self->destination_download_dir($destination_download_dir);
123 defined $destination_install_dir && $self->destination_install_dir($destination_install_dir);
124 defined $package_name && $self->package_name($package_name);
125 defined $directory_name && $self->directory_name($directory_name);
126  
127 return $self;
128 }
129  
130  
131 =head2 origin_download_dir
132  
133 Title : origin_download_dir
134 Usage : $obj->origin_download_dir($newval)
135 Function:
136 Example :
137 Returns : value of origin_download_dir (a scalar)
138 Args : on set, new value (a scalar or undef, optional)
139  
140  
141 =cut
142  
143 sub origin_download_dir{
144 my $self = shift;
145  
146 return $self->{'origin_download_dir'} = shift if @_;
147 return $self->{'origin_download_dir'} || $self->get_default('ORIGIN_DOWNLOAD_DIR');
148 }
149  
150  
151 =head2 destination_download_dir
152  
153 Title : destination_download_dir
154 Usage : $obj->destination_download_dir($newval)
155 Function:
156 Example :
157 Returns : value of destination_download_dir (a scalar)
158 Args : on set, new value (a scalar or undef, optional)
159  
160  
161 =cut
162  
163 sub destination_download_dir{
164 my $self = shift;
165  
166 return $self->{'destination_download_dir'} = shift if @_;
167 return $self->{'destination_download_dir'} || $self->get_default('DESTINATION_DOWNLOAD_DIR');
168 }
169  
170  
171 =head2 destination_install_dir
172  
173 Title : destination_install_dir
174 Usage : $obj->destination_install_dir($newval)
175 Function:
176 Example :
177 Returns : value of destination_install_dir (a scalar)
178 Args : on set, new value (a scalar or undef, optional)
179  
180  
181 =cut
182  
183 sub destination_install_dir{
184 my $self = shift;
185  
186 return $self->{'destination_install_dir'} = shift if @_;
187 return $self->{'destination_install_dir'} || $self->get_default('DESTINATION_INSTALL_DIR');
188 }
189  
190  
191 =head2 package_name
192  
193 Title : package_name
194 Usage : $obj->package_name($newval)
195 Function:
196 Example :
197 Returns : value of package_name (a scalar)
198 Args : on set, new value (a scalar or undef, optional)
199  
200  
201 =cut
202  
203 sub package_name{
204 my $self = shift;
205  
206 return $self->{'package_name'} = shift if @_;
207 return $self->{'package_name'} || $self->get_default('PACKAGE_NAME');
208 }
209  
210  
211 =head2 directory_name
212  
213 Title : directory_name
214 Usage : $obj->directory_name($newval)
215 Function:
216 Example :
217 Returns : value of directory_name (a scalar)
218 Args : on set, new value (a scalar or undef, optional)
219  
220  
221 =cut
222  
223 sub directory_name{
224 my $self = shift;
225  
226 return $self->{'directory_name'} = shift if @_;
227 return $self->{'directory_name'} || $self->get_default('DIRECTORY_NAME');
228 }
229  
230  
231 =head2 env_name
232  
233 Title : env_name
234 Usage :
235 Function:
236 Example :
237 Returns :
238 Args :
239  
240  
241 =cut
242  
243 sub env_name{
244 my $self = shift;
245 return $self->{'env_name'} = shift if @_;
246 return $self->{'env_name'} || $self->get_default('ENV_NAME');
247 }
248  
249 =head2 _remember_env
250  
251 Title : _remember_env
252 Usage :
253 Function:
254 Example :
255 Returns :
256 Args :
257  
258  
259 =cut
260  
261 sub _remember_env{
262 my ($self,@args) = @_;
263 my $dir;
264 $dir = $self->destination_install_dir;
265 $dir =~ s|/$||;
266 $dir .= "/" . $self->directory_name . "/" . $self->get_default('BIN_FOLDER');
267 my $env_name = $self->env_name;
268 print STDERR <<END;
269  
270  
271 You will need to enable \$$env_name to help bioperl find the
272 program. This can be done in (at least) two ways:
273 1. define an environmental variable \$$env_name:
274 export $env_name=$dir
275 or
276 2. include a definition of an environmental variable $env_name in
277 every script that will use the program in the corresponding
278 bioperl module.
279 BEGIN {\$ENV\{\'$env_name\'\}=$dir; }
280  
281 END
282 ;
283 }
284  
285  
286 =head2 _decompress
287  
288 Title : _decompress
289 Usage :
290 Function:
291 Example :
292 Returns :
293 Args :
294  
295  
296 =cut
297  
298 sub _decompress{
299 my ($self,@args) = @_;
300 my $call;
301 my $destination = $self->destination_download_dir . "/" . $self->package_name;;
302 my $destination_install_dir = $self->destination_install_dir;
303 if (($^O =~ /dec_osf|linux|unix|bsd|solaris|darwin/i)) {
304 $call = "tar xzvf $destination --directory=$destination_install_dir";
305 system("$call") == 0 or $self->throw("Error when trying to decompress package");
306 $call = "rm -f $destination";
307 system("$call") == 0 or $self->throw("Error when trying to delete compressed package");
308 } else {
309 $self->throw("_decompress not yet implemented in this platform");
310 }
311 }
312  
313  
314 =head2 download
315  
316 Title : download
317 Usage : $installer->download();
318 Function:
319 Example :
320 Returns :
321 Args :
322  
323  
324 =cut
325  
326 sub download{
327 my ($self,@args) = @_;
328 print "\n\nDownloading package...(this might take a while)\n\n";sleep 1;
329 my $file = $self->origin_download_dir;
330 $file =~ s|/$||;
331 $file .= "/" . $self->package_name;
332 my $destination = $self->destination_download_dir;
333 $destination =~ s|/$||;
334 $destination .= "/" . $self->package_name;;
335 my $ua = LWP::UserAgent->new;
336 my $response = $ua->request( GET($file), $destination );
337 die "Error at $file\n ", $response->status_line, "\n Aborting"
338 unless $response->is_success;
339 print "Package successfully downloaded at $destination.\n";
340  
341 return $self;
342 }
343  
344  
345 =head2 uninstall
346  
347 Title : uninstall
348 Usage : $installer->uninstall();
349 Function:
350 Example :
351 Returns :
352 Args :
353  
354  
355 =cut
356  
357 sub uninstall{
358 my ($self,@args) = @_;
359 my $call;
360 my $destination = $self->destination_install_dir;
361 $destination =~ s|/$||;
362 $destination .= "/" . $self->directory_name;
363 print "\n\nUninstalling now: this will delete the installed program\n\n";
364 if (($^O =~ /dec_osf|linux|unix|bsd|solaris|darwin/i)) {
365 $call = "rm -rf $destination";
366 system("$call") == 0 or die "Error when trying to delete installed program $?\n";
367 } else {
368 $self->throw("uninstall not yet implemented in this platform");
369 }
370 return $self;
371 }
372  
373  
374 1;