Auth0/UA/LWP.pm

filter: Statementstmt 50.0% 17 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 1 totaltotal 38.6% 22 / 57 CC 7 SCAR 34.2
CC
7
Cov
36%
request
56.0
__ANON__
2.0
BEGIN
1.0
CRAP 30.7
↑ Summary Auth0/Management/Base.pm »
1 package WebService::Auth0::UA::LWP;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Future;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶has options => (is=>'ro', required=>1, default=>sub { +{} });
Subroutine __ANON__: called CC=1 SCAR=0.0
9 has ua => (
10 is=>'ro',
11 lazy=>1,
12 required=>1,
13 0 ▶ default=>sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 LWP::UserAgent->new(
15 keep_alive => 10,
16 agent => 'WebService::Auth0::UA::LWP/1.0',
17 requests_redirectable => [],
18 0 %{ $_[0]->options });
19 },
20 1 );
21  
22 0 ▶sub request {
Subroutine request: not called CC=7 SCAR=40.3
Pod undocumented
23 0 my ($self, $request) = @_;
24 0 my $response = $self->ua->request($request);
25 0 my $json_err;
26 0 my $data = do {
27 # Required because I often see 204 no content but with
28 # application/json as the content type
29 0 ▶ if($response->code == 204) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->code == 204) { } 0 0 0
30 0 undef;
31 } else {
32 eval {
33 0 ▶ $response->content_type eq 'application/json' ?
Branch: 1 branch
BranchTrueFalseTotal
$response->content_type eq 'application/json' ? : 0 0 0
34 decode_json($response->decoded_content) :
35 $response;
36 0 ▶ } || do {
Condition0%0/3
eval { do { $response->content_type eq 'application/json' ? &decode_json(scalar $response->decoded_content) : $response } } || do { $json_err = $@ }
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { $response->content_type eq 'application/json' ? &decode_json(scalar $response->decoded_content) : $response } } || do { $json_err = $@ }
eval { do { $response->content_type eq 'application/json' ? &decode_json(scalar $response->decoded_content) : $response } } do { $json_err = $@ }
Truth table0%0/3
A || B
A= eval { do { $response->content_type eq 'application/json' ? &decode_json(scalar $response->decoded_content) : $response } }B= do { $json_err = $@ }
ABresult
1X1
011
000
37 0 $json_err = $@;
38 };
39 }
40 };
41  
42 0 ▶ if($json_err) {
Branch: 3 branches
BranchTrueFalseTotal
if ($json_err) { } 0 0 0
elsif ($response->is_success) { } 0 0 0
elsif ($response->is_redirect) { } 0 0 0
43 0 return Future->fail(
44 $json_err,
45 json => $request,
46 $response);
47 } elsif($response->is_success) {
48 0 return Future->done($data);
49 } elsif($response->is_redirect) {
50 0 return Future->done($response->header('location'), $data);
51 } else {
52 0 return Future->fail(
53 $response->message,
54 0 "http_${\$response->code}" => $request,
55 $data);
56 }
57 }
58  
59 1 1;
60  
61 =head1 NAME
62  
63 WebService::Auth0::UA::LWP - Use LWP for connection
64  
65 =head1 SYNOPSIS
66  
67  
68 =head1 DESCRIPTION
69  
70  
71 =head1 METHODS
72  
73 This class defines the following methods:
74  
75 =head1 SEE ALSO
76
77 L<LWP>, L<Futures>
78  
79 =head1 AUTHOR
80
81 See L<WebService::Auth0>
82
83 =head1 COPYRIGHT & LICENSE
84
85 See L<WebService::Auth0>
86  
87 =cut
88  
89 1 1;
↑ Summary Auth0/Management/Base.pm »