Plient/Handler/HTTPLite.pm

filter: Statementstmt 21.6% 13 / 60 Branchbran 7.6% 2 / 26 Conditioncond 0.0% 0 / 32 MC/DCmcdc 0.0% 0 / 17 Subroutinesub 20.0% 2 / 10 Podpod 0.0% 0 / 6 totaltotal 11.2% 17 / 151 CC 25 SCAR 36.7
CC
25
Cov
13%
__ANON__
56.0
add_headers
56.0
support_method
42.0
CRAP 39.2
« Plient/Handler/wget.pm ↑ Summary Plient/Protocol.pm »
1 package Plient::Handler::HTTPLite;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶require Plient::Handler unless $Plient::bundle_mode;
Branch: 1 branch
BranchTrueFalseTotal
unless $Plient::bundle_mode 5 0 5
6 5 our @ISA = 'Plient::Handler';
7 5 my ( $HTTPLite, %all_protocol, %protocol, %method );
8  
9 5 %all_protocol = ( http => undef );
10 0 ▶sub all_protocol { return \%all_protocol }
Subroutine all_protocol: not called CC=1 SCAR=6.9
Pod undocumented
11 0 ▶sub protocol { return \%protocol }
Subroutine protocol: not called CC=1 SCAR=6.9
Pod undocumented
12 0 ▶sub method { return \%method }
Subroutine method: not called CC=1 SCAR=6.9
Pod undocumented
13  
14 0 ▶sub support_method {
Subroutine support_method: not called CC=6 SCAR=37.4
Pod undocumented
15 0 my $class = shift;
16 0 my ( $method, $args ) = @_;
17 0 ▶ if ( $args
Branch: 1 branch
BranchTrueFalseTotal
if ($args and $args->{"content_type"} and $args->{"content_type"} =~ /form-data/) 0 0 0
Condition0%0/6
$args and $args->{"content_type"} and $args->{"content_type"} =~ /form-data/
!ll&&!rl&&r
000
$args and $args->{"content_type"}
!ll&&!rl&&r
000
MC/DC0%0/3
$args and $args->{"content_type"} and $args->{"content_type"} =~ /form-data/
$args $args->{"content_type"} $args->{"content_type"} =~ /form-data/
Truth table0%0/4
A and B and C
A= $argsB= $args->{"content_type"}C= $args->{"content_type"} =~ /form-data/
ABCresult
0XX0
10X0
1100
1111
18 && $args->{content_type}
19 && $args->{content_type} =~ 'form-data' )
20 {
21 0 return;
22 }
23  
24 0 ▶ if ( $ENV{http_proxy} && $ENV{http_proxy} =~ /@/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"http_proxy"} and $ENV{"http_proxy"} =~ /@/) 0 0 0
Condition0%0/3
$ENV{"http_proxy"} and $ENV{"http_proxy"} =~ /@/
!ll&&!rl&&r
000
MC/DC0%0/2
$ENV{"http_proxy"} and $ENV{"http_proxy"} =~ /@/
$ENV{"http_proxy"} $ENV{"http_proxy"} =~ /@/
Truth table0%0/3
A and B
A= $ENV{"http_proxy"}B= $ENV{"http_proxy"} =~ /@/
ABresult
0X0
100
111
25 # HTTPLite doesn't support proxy auth
26 0 return;
27 }
28  
29 0 return $class->SUPER::support_method(@_);
30 }
31  
32 5 my $inited;
33 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod undocumented
34 0 ▶ return if $inited;
Branch: 1 branch
BranchTrueFalseTotal
if $inited 0 0 0
35 0 $inited = 1;
36 0 ▶ eval { require HTTP::Lite } or return;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require HTTP::Lite } } or return 0 0 0
37 0 undef $protocol{http};
38 0 ▶ $method{http_get} = sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
39 0 my ( $uri, $args ) = @_;
40 0 my $http = HTTP::Lite->new;
41 0 add_headers( $http, $uri, $args );
42 0 ▶ $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"http_proxy"} 0 0 0
43 0 ▶ my $res = $http->request($uri) || '';
Condition0%0/2
$http->request($uri) || ''
l!l
00
MC/DC0%0/1
$http->request($uri) || ''
$http->request($uri)
Truth table0%0/2
A
A= $http->request($uri)
Aresult
11
00
44  
45 0 ▶ if ( $res == 200 || $res == 301 || $res == 302 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 200 or $res == 301 or $res == 302) { } 0 0 0
Condition0%0/6
$res == 200 or $res == 301 or $res == 302
l!l&&r!l&&!r
000
$res == 200 or $res == 301
l!l&&r!l&&!r
000
MC/DC0%0/3
$res == 200 or $res == 301 or $res == 302
$res == 200 $res == 301 $res == 302
Truth table0%0/4
A or B or C
A= $res == 200B= $res == 301C= $res == 302
ABCresult
1XX1
01X1
0011
0000
46  
47 # XXX TODO handle redirect
48 0 return $http->body;
49 }
50 else {
51 0 warn "failed to get $uri with HTTP::Lite: " . $res;
52 0 return;
53 }
54 0 };
55  
56 0 ▶ $method{http_post} = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
57 0 my ( $uri, $args ) = @_;
58 0 my $http = HTTP::Lite->new;
59 0 ▶ $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"http_proxy"} 0 0 0
60 0 add_headers( $http, $uri, $args );
61 0 ▶ $http->prepare_post( $args->{body_hash} ) if $args->{body_hash};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"body_hash"} 0 0 0
62 0 ▶ my $res = $http->request($uri) || '';
Condition0%0/2
$http->request($uri) || ''
l!l
00
MC/DC0%0/1
$http->request($uri) || ''
$http->request($uri)
Truth table0%0/2
A
A= $http->request($uri)
Aresult
11
00
63 0 ▶ if ( $res == 200 || $res == 301 || $res == 302 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res == 200 or $res == 301 or $res == 302) { } 0 0 0
Condition0%0/6
$res == 200 or $res == 301 or $res == 302
l!l&&r!l&&!r
000
$res == 200 or $res == 301
l!l&&r!l&&!r
000
MC/DC0%0/3
$res == 200 or $res == 301 or $res == 302
$res == 200 $res == 301 $res == 302
Truth table0%0/4
A or B or C
A= $res == 200B= $res == 301C= $res == 302
ABCresult
1XX1
01X1
0011
0000
64  
65 # XXX TODO handle redirect
66 0 return $http->body;
67 }
68 else {
69 0 warn "failed to post $uri with HTTP::Lite: " . $res;
70 0 return;
71 }
72 0 };
73  
74 0 return 1;
75 }
76  
77 0 ▶sub add_headers {
Subroutine add_headers: not called CC=7 SCAR=40.3
Pod undocumented
78 0 my ( $http, $uri, $args ) = @_;
79 0 ▶ my $headers = $args->{headers} || {};
Condition0%0/2
$args->{'headers'} || {}
l!l
00
MC/DC0%0/1
$args->{'headers'} || {}
$args->{'headers'}
Truth table0%0/2
A
A= $args->{'headers'}
Aresult
11
00
80 0 for my $k ( keys %$headers ) {
81 0 $http->add_req_header( $k, $headers->{$k} );
82 }
83  
84 0 ▶ if ( $args->{user} && defined $args->{password} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"user"} and defined $args->{"password"}) 0 0 0
Condition0%0/3
$args->{"user"} and defined $args->{"password"}
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"user"} and defined $args->{"password"}
$args->{"user"} defined $args->{"password"}
Truth table0%0/3
A and B
A= $args->{"user"}B= defined $args->{"password"}
ABresult
0X0
100
111
85 0 ▶ my $method = lc $args->{auth_method} || 'basic';
Condition0%0/2
lc $args->{'auth_method'} || 'basic'
l!l
00
MC/DC0%0/1
lc $args->{'auth_method'} || 'basic'
lc $args->{'auth_method'}
Truth table0%0/2
A
A= lc $args->{'auth_method'}
Aresult
11
00
86 0 ▶ if ( $method eq 'basic' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq 'basic') { } 0 0 0
87 0 require MIME::Base64;
88 0 $http->add_req_header( "Authorization",
89 'Basic '
90 . MIME::Base64::encode_base64( "$args->{user}:$args->{password}", '' )
91 );
92 }
93 else {
94 0 die "aborting: unsupported auth method: $method";
95 }
96 }
97 }
98  
99 5 ▶__PACKAGE__->_add_to_plient if $Plient::bundle_mode;
Branch: 1 branch
BranchTrueFalseTotal
if $Plient::bundle_mode 0 5 5
100  
101 5 1;
102  
103 __END__
« Plient/Handler/wget.pm ↑ Summary Plient/Protocol.pm »