line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Alien::Build::Plugin::Fetch::Wget; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1512
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
5
|
2
|
|
|
2
|
|
47
|
use 5.008004; |
|
2
|
|
|
|
|
6
|
|
6
|
2
|
|
|
2
|
|
345
|
use Alien::Build::Plugin; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
16
|
|
7
|
2
|
|
|
2
|
|
13
|
use File::Temp qw( tempdir ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
129
|
|
8
|
2
|
|
|
2
|
|
10
|
use Path::Tiny qw( path ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
97
|
|
9
|
2
|
|
|
2
|
|
13
|
use File::Which qw( which ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
110
|
|
10
|
2
|
|
|
2
|
|
11
|
use Capture::Tiny qw( capture capture_merged ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
103
|
|
11
|
2
|
|
|
2
|
|
510
|
use File::chdir; |
|
2
|
|
|
|
|
2602
|
|
|
2
|
|
|
|
|
269
|
|
12
|
2
|
|
|
2
|
|
20
|
use List::Util qw( pairmap ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1587
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# ABSTRACT: Plugin for fetching files using wget |
15
|
|
|
|
|
|
|
our $VERSION = '2.47'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _wget |
19
|
|
|
|
|
|
|
{ |
20
|
2
|
50
|
|
2
|
|
129
|
my $wget = defined $ENV{WGET} ? which($ENV{WGET}) : which('wget'); |
21
|
2
|
50
|
|
|
|
198
|
return undef unless defined $wget; |
22
|
2
|
|
|
2
|
|
62
|
my $output = capture_merged { system $wget, '--help' }; |
|
2
|
|
|
|
|
2599
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# The wget that BusyBox implements does not follow that same interface |
25
|
|
|
|
|
|
|
# as GNU wget and may not check ssl certs which is not good. |
26
|
2
|
50
|
|
|
|
13079
|
return undef if $output =~ /BusyBox/; |
27
|
2
|
|
|
|
|
24
|
return $wget; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
has wget_command => sub { _wget() }; |
31
|
|
|
|
|
|
|
has ssl => 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# when bootstrapping we have to specify this plugin as a prereq |
34
|
|
|
|
|
|
|
# 1 is the default so that when this plugin is used directly |
35
|
|
|
|
|
|
|
# you also get the prereq |
36
|
|
|
|
|
|
|
has bootstrap_ssl => 1; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub init |
39
|
|
|
|
|
|
|
{ |
40
|
1
|
|
|
1
|
1
|
4
|
my($self, $meta) = @_; |
41
|
|
|
|
|
|
|
|
42
|
1
|
50
|
|
|
|
14
|
$meta->add_requires('configure', 'Alien::Build::Plugin::Fetch::Wget' => '1.19') |
43
|
|
|
|
|
|
|
if $self->bootstrap_ssl; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
$meta->register_hook( |
46
|
|
|
|
|
|
|
fetch => sub { |
47
|
3
|
|
|
3
|
|
10
|
my($build, $url, %options) = @_; |
48
|
3
|
|
66
|
|
|
25
|
$url ||= $meta->prop->{start_url}; |
49
|
|
|
|
|
|
|
|
50
|
3
|
|
|
|
|
32
|
my($scheme) = $url =~ /^([a-z0-9]+):/i; |
51
|
|
|
|
|
|
|
|
52
|
3
|
50
|
33
|
|
|
16
|
if($scheme eq 'http' || $scheme eq 'https') |
53
|
|
|
|
|
|
|
{ |
54
|
3
|
|
|
|
|
14
|
local $CWD = tempdir( CLEANUP => 1 ); |
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
|
|
1258
|
my @headers; |
57
|
3
|
50
|
|
|
|
16
|
if(my $headers = $options{http_headers}) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
0
|
|
|
|
0
|
if(ref $headers eq 'ARRAY') |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
|
|
0
|
my @copy = @$headers; |
62
|
0
|
|
|
|
|
0
|
my %headers; |
63
|
0
|
|
|
|
|
0
|
while(@copy) |
64
|
|
|
|
|
|
|
{ |
65
|
0
|
|
|
|
|
0
|
my $key = shift @copy; |
66
|
0
|
|
|
|
|
0
|
my $value = shift @copy; |
67
|
0
|
|
|
|
|
0
|
push @{ $headers{$key} }, $value; |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
0
|
@headers = pairmap { "--header=$a: @{[ join ', ', @$b ]}" } %headers; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
0
|
$build->log("Fetch for $url with http_headers that is not an array reference"); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
3
|
|
|
|
|
25
|
my($stdout, $stderr) = $self->_execute( |
78
|
|
|
|
|
|
|
$build, |
79
|
|
|
|
|
|
|
$self->wget_command, |
80
|
|
|
|
|
|
|
'-k', '--content-disposition', '-S', |
81
|
|
|
|
|
|
|
@headers, |
82
|
|
|
|
|
|
|
$url, |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
2
|
|
|
|
|
11
|
my($path) = path('.')->children; |
86
|
2
|
50
|
|
|
|
464
|
die "no file found after wget" unless $path; |
87
|
2
|
|
|
|
|
29
|
my($type) = $stderr =~ /Content-Type:\s*(.*?)$/m; |
88
|
2
|
50
|
|
|
|
19
|
$type =~ s/;.*$// if $type; |
89
|
2
|
100
|
|
|
|
12
|
if($type eq 'text/html') |
90
|
|
|
|
|
|
|
{ |
91
|
|
|
|
|
|
|
return { |
92
|
1
|
|
|
|
|
11
|
type => 'html', |
93
|
|
|
|
|
|
|
base => $url, |
94
|
|
|
|
|
|
|
content => scalar $path->slurp, |
95
|
|
|
|
|
|
|
}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
else |
98
|
|
|
|
|
|
|
{ |
99
|
|
|
|
|
|
|
return { |
100
|
1
|
|
|
|
|
7
|
type => 'file', |
101
|
|
|
|
|
|
|
filename => $path->basename, |
102
|
|
|
|
|
|
|
path => $path->absolute->stringify, |
103
|
|
|
|
|
|
|
}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
else |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
|
|
0
|
die "scheme $scheme is not supported by the Fetch::Wget plugin"; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
}, |
111
|
1
|
50
|
|
|
|
4
|
) if $self->wget_command; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub _execute |
115
|
|
|
|
|
|
|
{ |
116
|
3
|
|
|
3
|
|
17
|
my($self, $build, @command) = @_; |
117
|
3
|
|
|
|
|
49
|
$build->log("+ @command"); |
118
|
|
|
|
|
|
|
my($stdout, $stderr, $err) = capture { |
119
|
3
|
|
|
3
|
|
3113
|
system @command; |
120
|
3
|
|
|
|
|
1380
|
$?; |
121
|
3
|
|
|
|
|
155
|
}; |
122
|
3
|
100
|
|
|
|
2210
|
if($err) |
123
|
|
|
|
|
|
|
{ |
124
|
1
|
|
|
|
|
6
|
chomp $stderr; |
125
|
1
|
|
|
|
|
11
|
$stderr = [split /\n/, $stderr]->[-1]; |
126
|
1
|
|
|
|
|
22
|
die "error in wget fetch: $stderr"; |
127
|
|
|
|
|
|
|
} |
128
|
2
|
|
|
|
|
15
|
($stdout, $stderr); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
__END__ |