File Coverage

lib/Bio/MLST/Download/Downloadable.pm
Criterion Covered Total %
statement 38 39 97.4
branch 5 6 83.3
condition n/a
subroutine 10 10 100.0
pod n/a
total 53 55 96.3


line stmt bran cond sub pod time code
1             package Bio::MLST::Download::Downloadable;
2             # ABSTRACT: Moose Role to download everything data
3             $Bio::MLST::Download::Downloadable::VERSION = '2.1.1706216';
4              
5              
6 6     6   5794 use Moose::Role;
  6         19044  
  6         18  
7 6     6   24823 use File::Copy;
  6         6945  
  6         314  
8 6     6   27 use File::Basename;
  6         8  
  6         295  
9 6     6   1641 use LWP::Simple;
  6         116431  
  6         51  
10 6     6   1755 use File::Path 2.06 qw(make_path);
  6         102  
  6         1684  
11              
12             sub _download_file
13             {
14 7     7   66 my ($self, $filename,$destination_directory) = @_;
15            
16             # copy if its on the same filesystem
17 7 100       95 if(-e $filename)
18             {
19 5         20 copy($filename, $destination_directory);
20             }
21             else
22             {
23 2         8 my $status = getstore($filename, join('/',($destination_directory,$self->_get_filename_from_url($filename))));
24 2 100       14 die "Something went wrong, got a $status status code" if is_error($status);
25             }
26 6         1328 1;
27             }
28              
29             sub _get_filename_from_url
30             {
31 5     5   12 my ($self, $filename) = @_;
32 5 50       40 if($filename =~ m!/([^/]+)$!)
33             {
34 5         40 return $1;
35             }
36            
37 0         0 return int(rand(10000)).".tfa";
38             }
39              
40             sub _build_destination_directory
41             {
42 1     1   1 my ($self) = @_;
43 1         21 my $destination_directory = join('/',($self->base_directory,$self->_sub_directory));
44 1         149 make_path($destination_directory);
45 1         92 make_path(join('/',($destination_directory,'alleles')));
46 1         86 make_path(join('/',($destination_directory,'profiles')));
47 1         25 return $destination_directory;
48             }
49              
50             sub _sub_directory
51             {
52 1     1   1 my ($self) = @_;
53 1         19 my $combined_name = join('_',($self->species));
54 1         2 $combined_name =~ s!\.$!!gi;
55 1         4 $combined_name =~ s!\W!_!gi;
56 1         2 return $combined_name;
57             }
58              
59 6     6   29 no Moose;
  6         5  
  6         42  
60             1;
61              
62             __END__
63              
64             =pod
65              
66             =encoding UTF-8
67              
68             =head1 NAME
69              
70             Bio::MLST::Download::Downloadable - Moose Role to download everything data
71              
72             =head1 VERSION
73              
74             version 2.1.1706216
75              
76             =head1 SYNOPSIS
77              
78             Moose Role to download everything data
79              
80             with 'Bio::MLST::Download::Downloadable';
81              
82             =head1 SEE ALSO
83              
84             =over 4
85              
86             =item *
87              
88             L<Bio::MLST::Download::Database>
89              
90             =item *
91              
92             L<Bio::MLST::Download::Databases>
93              
94             =back
95              
96             =head1 AUTHOR
97              
98             Andrew J. Page <ap13@sanger.ac.uk>
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is Copyright (c) 2012 by Wellcome Trust Sanger Institute.
103              
104             This is free software, licensed under:
105              
106             The GNU General Public License, Version 3, June 2007
107              
108             =cut