blib/lib/Alien/Build/Plugin/Fetch/LWP.pm

filter: Statementstmt 89.3% 42 / 47 Branchbran 57.1% 8 / 14 Conditioncond 41.1% 7 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 67.0% 65 / 97 CC 14 SCAR 22.2
CC
14
Cov
73%
__ANON__
14.9
init
6.1
BEGIN
1.0
CRAP 9.2
« blib/lib/Alien/Base/Wrapper.pm ↑ Summary blib/lib/Alien/Build/Plugin/Extract/Negotiate.pm »
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
l!l&&r!l&&!r
430
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
ABresult
1X1
011
000
25 7 $self->url($meta->prop->{start_url});
26 7 ▶ $self->url || Carp::croak('url is a required property');
Branch: 1 branch
BranchTrueFalseTotal
$self->url or Carp::croak("url is a required property") 7 0 7
27  
28 7 ▶ if($self->url =~ /^https:/ || $self->ssl)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->url =~ /^https:/ or $self->ssl) 0 7 7
Condition33%1/3
$self->url =~ /^https:/ or $self->ssl
l!l&&r!l&&!r
007
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
510
MC/DC0%0/2
$url ||= $self->url
$url $self->url
Truth table66%2/3
A ||= B
A= $urlB= $self->url
ABresult
1X1
011
000
36  
37 6 my @headers;
38 6 ▶ if(my $headers = $options{http_headers})
Branch: 1 branch
BranchTrueFalseTotal
if (my $headers = $options{"http_headers"}) 0 6 6
39 {
40 0 ▶ if(ref $headers eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $headers eq 'ARRAY') { } 0 0 0
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
BranchTrueFalseTotal
unless $res->is_success 1 5 6
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
BranchTrueFalseTotal
if ($type eq 'text/html') { } 4 1 5
elsif ($type eq 'text/ftp-dir-listing') { } 0 1 1
64 {
65 return {
66 4 ▶ type => 'html',
Condition33%1/3
$res->decoded_content || $res->content
l!l&&r!l&&!r
400
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
ABresult
1X1
011
000
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
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
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'
l!l
10
MC/DC0%0/1
$filename || 'downloadedfile'
$filename
Truth table50%1/2
A
A= $filename
Aresult
11
00
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__
« blib/lib/Alien/Base/Wrapper.pm ↑ Summary blib/lib/Alien/Build/Plugin/Extract/Negotiate.pm »