Tester/UA/LWP.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 75.0% 9 / 12 Conditioncond 42.8% 3 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 5 totaltotal 81.5% 75 / 92 CC 12 SCAR 12.3
CC
12
Cov
88%
set_cookie
7.0
request
5.0
__ANON__
2.0
CRAP 3.4
« Tester/Role/Result.pm ↑ Summary Tester/Sugar.pm »
1 3 ▶use v5.14.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package JMAP::Tester::UA::LWP 0.113;
5  
6 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 with 'JMAP::Tester::Role::UA';
8  
9 3 ▶use experimental 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 has lwp => (
15 is => 'ro',
16 lazy => 1,
17 3 ▶ default => sub ($self) {
Subroutine __ANON__: called CC=2 SCAR=7.1
18 3 require LWP::UserAgent;
19 3 my $lwp = LWP::UserAgent->new(keep_alive => 1);
20 3 $lwp->cookie_jar({});
21  
22 3 $lwp->default_header('Content-Type' => 'application/json');
23  
24 3 ▶ if ($ENV{IGNORE_INVALID_CERT}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"IGNORE_INVALID_CERT"}) 0 3 3
25 0 $lwp->ssl_opts(SSL_verify_mode => 0, verify_hostname => 0);
26 }
27  
28 3 return $lwp;
29 },
30 3 );
31  
32 4 ▶sub set_cookie ($self, $arg) {
Subroutine set_cookie: called CC=6 SCAR=19.5
Pod undocumented
33 4 for (qw(api_uri name value)) {
34 9 ▶ Carp::confess("can't set_cookie without $_") unless $arg->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $arg->{$_} 3 6 9
35 }
36  
37 1 my $uri = URI->new($arg->{api_uri});
38  
39 $self->lwp->cookie_jar->set_cookie(
40 1,
41 $arg->{name},
42 $arg->{value},
43 '/',
44 $arg->{domain} // $uri->host,
45 $uri->port,
46 0,
47 ($uri->port == 443 ? 1 : 0),
48 86400,
49 0,
50 $arg->{rest} || {},
51 1 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$uri->port == 443 ? : 1 0 1
Condition40%2/5
$arg->{"domain"} // $uri->host
l!l&&r!l&&!r
010
$arg->{'rest'} || {}
l!l
01
MC/DC0%0/2
$arg->{"domain"} // $uri->host
$arg->{"domain"} $uri->host
MC/DC0%0/1
$arg->{'rest'} || {}
$arg->{'rest'}
Truth table33%1/3
A // B
A= $arg->{"domain"}B= $uri->host
ABresult
1X1
011
000
Truth table50%1/2
A
A= $arg->{'rest'}
Aresult
11
00
52 }
53  
54 1 ▶sub scan_cookies ($self, $callback) {
Subroutine scan_cookies: called CC=1 SCAR=0.0
Pod undocumented
55 1 return $self->lwp->cookie_jar->scan($callback);
56 }
57  
58 1 ▶sub get_default_header ($self, $name) {
Subroutine get_default_header: called CC=1 SCAR=0.0
Pod undocumented
59 1 return scalar $self->lwp->default_header($name);
60 }
61  
62 1 ▶sub set_default_header ($self, $name, $value) {
Subroutine set_default_header: called CC=1 SCAR=0.0
Pod undocumented
63 1 $self->lwp->default_header($name, $value);
64 1 return;
65 }
66  
67 12 ▶sub request ($self, $tester, $req, $log_type, $log_extra = undef) {
Subroutine request: called CC=5 SCAR=16.1
Pod undocumented
68 12 ▶ Carp::cluck("something very strange happened") unless $tester->can('_logger');
Branch: 1 branch
BranchTrueFalseTotal
unless $tester->can("_logger") 0 12 12
69 12 my $logger = $tester->_logger;
70  
71 12 ▶ my $log_method = "log_" . ($log_type // 'jmap') . '_request';
Condition50%1/2
$log_type // "jmap"
l!l
120
MC/DC0%0/1
$log_type // "jmap"
$log_type
Truth table50%1/2
A
A= $log_type
Aresult
11
00
72 12 ▶ if ($logger->can($log_method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($logger->can($log_method)) 7 5 12
73 7 ▶ $self->lwp->set_my_handler(request_send => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
74 7 my ($req) = @_;
75 7 ▶ $logger->$log_method(
Branch: 1 branch
BranchTrueFalseTotal
$log_extra ? : 4 3 7
76 $tester,
77 {
78 ($log_extra ? %$log_extra : ()),
79 http_request => $req,
80 }
81 );
82 7 return;
83 7 });
84 }
85  
86 12 my $http_res = $self->lwp->request($req);
87  
88 # Clear our handler, or it will get called for
89 # any http request our ua makes!
90 12 $self->lwp->set_my_handler(request_send => undef);
91  
92 12 return Future->done($http_res);
93 }
94  
95 3 ▶no Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 3 1;
97  
98 __END__
« Tester/Role/Result.pm ↑ Summary Tester/Sugar.pm »