« blib/lib/Alien/Build/Plugin/Fetch/Wget.pm
↑ Summary
blib/lib/Alien/Build/Plugin/PkgConfig/CommandLine.pm »
| 1 | package Alien::Build::Plugin::Core::Download; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 57 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 57 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 57 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 57 | ▶ | use Alien::Build::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 57 | ▶ | use Path::Tiny (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 57 | ▶ | use Alien::Build::Util qw( _mirror ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Core download plugin | ||||||||||||||||||||||||||||
| 11 | 57 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub _hook | ||||||||||||||||||||||||||||
| 15 | 45 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_hook: called CC=26 SCAR=36.2
| |||||||||||||||||||||||||||||
| 16 | 45 | my($build) = @_; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 45 | my $res = $build->fetch; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 41 | ▶ | if($res->{type} =~ /^(?:html|dir_listing)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | 4 | my $type = $res->{type}; | |||||||||||||||||||||||||||
| 23 | 4 | $type =~ s/_/ /; | |||||||||||||||||||||||||||
| 24 | 4 | $build->log("decoding $type"); | |||||||||||||||||||||||||||
| 25 | 4 | $res = $build->decode($res); | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 41 | ▶ | if($res->{type} eq 'list') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 14 | my $orig = $res; | |||||||||||||||||||||||||||
| 31 | 14 | $res = $build->prefer($res); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 14 | my @exclude; | |||||||||||||||||||||||||||
| 34 | 14 | ▶ | if($build->meta->prop->{start_url} =~ /^https:/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 5 | @{ $res->{list} } = grep { | |||||||||||||||||||||||||||
| 37 | 307 | ▶ | $_->{url} =~ /https:/ ? 1 : do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 2 | push @exclude, $_->{url}; | |||||||||||||||||||||||||||
| 39 | 2 | 0; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 5 | } @{ $res->{list} }; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 14 | ▶ | if(@{ $res->{list} } == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 0 | my @excluded = map { $_->{url} } @{ $orig->{list} }; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if(@excluded) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if(@excluded > 15) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | { | ||||||||||||||||||||||||||||
| 51 | 0 | splice @excluded , 14; | |||||||||||||||||||||||||||
| 52 | 0 | push @excluded, '...'; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | 0 | $build->log("These files were excluded by the filter stage:"); | |||||||||||||||||||||||||||
| 55 | 0 | $build->log("excluded $_") for @excluded; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | else | ||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||
| 59 | 0 | $build->log("No files found prior to the filter stage"); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 0 | die "no matching files in listing"; | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 14 | my $version = $res->{list}->[0]->{version}; | |||||||||||||||||||||||||||
| 64 | 14 | my($pick, @other) = map { $_->{url} } @{ $res->{list} }; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 14 | ▶ | if(@other > 8) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 3 | splice @other, 7; | |||||||||||||||||||||||||||
| 69 | 3 | push @other, '...'; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 14 | $build->log("candidate *$pick"); | |||||||||||||||||||||||||||
| 72 | 14 | $build->log("candidate $_") for @other; | |||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 14 | ▶ | if(@exclude) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | { | ||||||||||||||||||||||||||||
| 76 | 2 | ▶ | if(@exclude > 8) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||
| 78 | 0 | splice @exclude, 7; | |||||||||||||||||||||||||||
| 79 | 0 | push @exclude, '...'; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 2 | $build->log("excluded insecure URLs:"); | |||||||||||||||||||||||||||
| 82 | 2 | $build->log($_) for @exclude; | |||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 14 | $res = $build->fetch($pick); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 14 | ▶ | if($version) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 11 | $version =~ s/\.+$//; | |||||||||||||||||||||||||||
| 90 | 11 | $build->log("setting version based on archive to $version"); | |||||||||||||||||||||||||||
| 91 | 11 | $build->runtime_prop->{version} = $version; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 41 | ▶ | if($res->{type} eq 'file') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||||||||
| 97 | 41 | my $alienfile = $res->{filename}; | |||||||||||||||||||||||||||
| 98 | 41 | $build->log("downloaded $alienfile"); | |||||||||||||||||||||||||||
| 99 | 41 | ▶ | if($res->{content}) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | 28 | my $tmp = Alien::Build::TempDir->new($build, "download"); | |||||||||||||||||||||||||||
| 102 | 28 | my $path = Path::Tiny->new("$tmp/$alienfile"); | |||||||||||||||||||||||||||
| 103 | 28 | $path->spew_raw($res->{content}); | |||||||||||||||||||||||||||
| 104 | 28 | $build->install_prop->{download} = $path->stringify; | |||||||||||||||||||||||||||
| 105 | 28 | $build->install_prop->{complete}->{download} = 1; | |||||||||||||||||||||||||||
| 106 | 28 | ▶ | $build->install_prop->{download_detail}->{"$path"}->{protocol} = $res->{protocol} if defined $res->{protocol}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 28 | return $build; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | elsif($res->{path}) | ||||||||||||||||||||||||||||
| 110 | { | ||||||||||||||||||||||||||||
| 111 | 13 | ▶ | if(defined $res->{tmp} && !$res->{tmp}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $res->{"tmp"} and not $res->{"tmp"}
MC/DC100%2/2
defined $res->{"tmp"} and not $res->{"tmp"}
defined $res->{"tmp"}
not $res->{"tmp"}
Truth table100%3/3
A and not(B)
A= defined $res->{"tmp"}B= not $res->{"tmp"}
| |||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||
| 113 | 11 | ▶ | if(-e $res->{path}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||
| 115 | 11 | $build->install_prop->{download} = $res->{path}; | |||||||||||||||||||||||||||
| 116 | 11 | $build->install_prop->{complete}->{download} = 1; | |||||||||||||||||||||||||||
| 117 | 11 | ▶ | $build->install_prop->{download_detail}->{$res->{path}}->{protocol} = $res->{protocol} if defined $res->{protocol}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | else | ||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 0 | die "not a file or directory: @{[ $res->{path} ]}"; | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | else | ||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 2 | my $from = Path::Tiny->new($res->{path}); | |||||||||||||||||||||||||||
| 127 | 2 | my $tmp = Alien::Build::TempDir->new($build, "download"); | |||||||||||||||||||||||||||
| 128 | 2 | my $to = Path::Tiny->new("$tmp/@{[ $from->basename ]}"); | |||||||||||||||||||||||||||
| 129 | 2 | ▶ | if(-d $res->{path}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||||||||
| 131 | # Please note: _mirror and Alien::Build::Util are ONLY | ||||||||||||||||||||||||||||
| 132 | # allowed to be used by core plugins. If you are writing | ||||||||||||||||||||||||||||
| 133 | # a non-core plugin it may be removed. That is why it | ||||||||||||||||||||||||||||
| 134 | # is private. | ||||||||||||||||||||||||||||
| 135 | 0 | _mirror $from, $to; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | else | ||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 2 | require File::Copy; | |||||||||||||||||||||||||||
| 140 | 2 | ▶ | File::Copy::copy( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | "$from" => "$to", | ||||||||||||||||||||||||||||
| 142 | ) || die "copy $from => $to failed: $!"; | ||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | 2 | $build->install_prop->{download} = $to->stringify; | |||||||||||||||||||||||||||
| 145 | 2 | $build->install_prop->{complete}->{download} = 1; | |||||||||||||||||||||||||||
| 146 | 2 | ▶ | $build->install_prop->{download_detail}->{"$to"}->{protocol} = $res->{protocol} if defined $res->{protocol}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 13 | return $build; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | die "file without content or path"; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | 0 | die "unknown fetch response type: @{[ $res->{type} ]}"; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | sub init | ||||||||||||||||||||||||||||
| 156 | 399 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 399 | my($self, $meta) = @_; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 399 | $meta->default_hook(download => \&_hook); | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 57 | 1; | |||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | __END__ | ||||||||||||||||||||||||||||