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