line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
940
|
use v5.14.0; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
55
|
|
2
|
1
|
|
|
1
|
|
8
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
170
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package OS::Package::Artifact::Role::Download; |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
809
|
use FileHandle; |
|
1
|
|
|
|
|
16518
|
|
|
1
|
|
|
|
|
5
|
|
7
|
1
|
|
|
1
|
|
20655
|
use HTTP::Tiny; |
|
1
|
|
|
|
|
34760
|
|
|
1
|
|
|
|
|
46
|
|
8
|
1
|
|
|
1
|
|
50
|
use OS::Package::Log; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Path::Tiny; |
10
|
|
|
|
|
|
|
use Role::Tiny; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Provides the download method for Artifact role. |
13
|
|
|
|
|
|
|
our $VERSION = '0.2.6'; # VERSION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub download { |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if ( !$self->url ) { |
20
|
|
|
|
|
|
|
$LOGGER->debug('did not define url'); |
21
|
|
|
|
|
|
|
return 1; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( path( $self->savefile )->exists ) { |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'distfile exists: %s', $self->savefile ); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( $self->validate ) { |
29
|
|
|
|
|
|
|
return 1; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
|
|
|
|
|
|
$LOGGER->warn( sprintf 'removing bad distfile: %s', |
33
|
|
|
|
|
|
|
$self->savefile ); |
34
|
|
|
|
|
|
|
path( $self->savefile )->remove; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$LOGGER->info( sprintf 'downloading: %s', $self->distfile ); |
39
|
|
|
|
|
|
|
$LOGGER->debug( sprintf 'saving to: %s', $self->savefile ); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $response = HTTP::Tiny->new->get( $self->url ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $save_file = path( $self->savefile )->realpath; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$save_file->spew( $response->{content} ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if ( !$self->validate ) { |
48
|
|
|
|
|
|
|
$LOGGER->logcroak( sprintf 'cannot download: %s', $self->url ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
1; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
__END__ |