| 1 | package Alien::Build::Plugin::Fetch::LWP; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008004; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Alien::Build::Plugin; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # ABSTRACT: Plugin for fetching files using LWP | ||||||||||||||||||||||||||||
| 10 | 3 | our $VERSION = '2.88'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | has '+url' => ''; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 3 | has ssl => 0; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub init | ||||||||||||||||||||||||||||
| 19 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=5 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 7 | my($self, $meta) = @_; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 7 | $meta->add_requires('share' => 'LWP::UserAgent' => 0 ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | $meta->prop->{start_url} ||= $self->url; | ||||||||||||||||||||||||||
|
Condition66%2/3
$meta->prop->{"start_url"} ||= $self->url
MC/DC0%0/2
$meta->prop->{"start_url"} ||= $self->url
$meta->prop->{"start_url"}
$self->url
Truth table66%2/3
A ||= B
A= $meta->prop->{"start_url"}B= $self->url
| |||||||||||||||||||||||||||||
| 25 | 7 | $self->url($meta->prop->{start_url}); | |||||||||||||||||||||||||||
| 26 | 7 | ▶ | $self->url || Carp::croak('url is a required property'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 7 | ▶ | if($self->url =~ /^https:/ || $self->ssl) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->url =~ /^https:/ or $self->ssl
MC/DC0%0/2
$self->url =~ /^https:/ or $self->ssl
$self->url =~ /^https:/
$self->ssl
Truth table33%1/3
A or B
A= $self->url =~ /^https:/B= $self->ssl
| |||||||||||||||||||||||||||||
| 29 | { | ||||||||||||||||||||||||||||
| 30 | 0 | $meta->add_requires('share' => 'LWP::Protocol::https' => 0 ); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | $meta->register_hook( fetch => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=10 SCAR=27.0
| |||||||||||||||||||||||||||||
| 34 | 6 | my($build, $url, %options) = @_; | |||||||||||||||||||||||||||
| 35 | 6 | ▶ | $url ||= $self->url; | ||||||||||||||||||||||||||
|
Condition66%2/3
$url ||= $self->url
MC/DC0%0/2
$url ||= $self->url
$url
$self->url
Truth table66%2/3
A ||= B
A= $urlB= $self->url
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 6 | my @headers; | |||||||||||||||||||||||||||
| 38 | 6 | ▶ | if(my $headers = $options{http_headers}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if(ref $headers eq 'ARRAY') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 0 | @headers = @$headers; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else | ||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||
| 46 | 0 | $build->log("Fetch for $url with http_headers that is not an array reference"); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 6 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||
| 51 | 6 | $ua->env_proxy; | |||||||||||||||||||||||||||
| 52 | 6 | my $res = $ua->get($url, @headers); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 6 | my($protocol) = $url =~ /^([a-z]+):/; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 6 | ▶ | die "error fetching $url: @{[ $res->status_line ]}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | unless $res->is_success; | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 5 | my($type, $charset) = $res->content_type_charset; | |||||||||||||||||||||||||||
| 60 | 5 | my $base = $res->base; | |||||||||||||||||||||||||||
| 61 | 5 | my $filename = $res->filename; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 5 | ▶ | if($type eq 'text/html') | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 64 | { | ||||||||||||||||||||||||||||
| 65 | return { | ||||||||||||||||||||||||||||
| 66 | 4 | ▶ | type => 'html', | ||||||||||||||||||||||||||
|
Condition33%1/3
$res->decoded_content || $res->content
MC/DC0%0/2
$res->decoded_content || $res->content
$res->decoded_content
$res->content
Truth table33%1/3
A || B
A= $res->decoded_contentB= $res->content
| |||||||||||||||||||||||||||||
| 67 | charset => $charset, | ||||||||||||||||||||||||||||
| 68 | base => "$base", | ||||||||||||||||||||||||||||
| 69 | content => $res->decoded_content || $res->content, | ||||||||||||||||||||||||||||
| 70 | protocol => $protocol, | ||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | elsif($type eq 'text/ftp-dir-listing') | ||||||||||||||||||||||||||||
| 74 | { | ||||||||||||||||||||||||||||
| 75 | return { | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | type => 'dir_listing', | ||||||||||||||||||||||||||
|
Condition0%0/3
$res->decoded_content || $res->content
MC/DC0%0/2
$res->decoded_content || $res->content
$res->decoded_content
$res->content
Truth table0%0/3
A || B
A= $res->decoded_contentB= $res->content
| |||||||||||||||||||||||||||||
| 77 | base => "$base", | ||||||||||||||||||||||||||||
| 78 | content => $res->decoded_content || $res->content, | ||||||||||||||||||||||||||||
| 79 | protocol => $protocol, | ||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | else | ||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||
| 84 | return { | ||||||||||||||||||||||||||||
| 85 | 1 | ▶ | type => 'file', | ||||||||||||||||||||||||||
|
Condition50%1/2
$filename || 'downloadedfile'
MC/DC0%0/1
$filename || 'downloadedfile'
$filename
Truth table50%1/2
A
A= $filename
| |||||||||||||||||||||||||||||
| 86 | filename => $filename || 'downloadedfile', | ||||||||||||||||||||||||||||
| 87 | content => $res->content, | ||||||||||||||||||||||||||||
| 88 | protocol => $protocol, | ||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 7 | }); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 7 | $self; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 3 | 1; | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | __END__ | ||||||||||||||||||||||||||||