| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WebService::Auth0::UA::LWP; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 95309 | use Moo; | 
|  | 1 |  |  |  |  | 8845 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 4 | 1 |  |  | 1 |  | 1752 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 37033 |  | 
|  | 1 |  |  |  |  | 30 |  | 
| 5 | 1 |  |  | 1 |  | 377 | use JSON::MaybeXS; | 
|  | 1 |  |  |  |  | 4650 |  | 
|  | 1 |  |  |  |  | 52 |  | 
| 6 | 1 |  |  | 1 |  | 548 | use Future; | 
|  | 1 |  |  |  |  | 6624 |  | 
|  | 1 |  |  |  |  | 235 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | has options => (is=>'ro', required=>1, default=>sub { +{} }); | 
| 9 |  |  |  |  |  |  | has ua => ( | 
| 10 |  |  |  |  |  |  | is=>'ro', | 
| 11 |  |  |  |  |  |  | lazy=>1, | 
| 12 |  |  |  |  |  |  | required=>1, | 
| 13 |  |  |  |  |  |  | default=>sub { | 
| 14 |  |  |  |  |  |  | LWP::UserAgent->new( | 
| 15 |  |  |  |  |  |  | keep_alive => 10, | 
| 16 |  |  |  |  |  |  | agent => 'WebService::Auth0::UA::LWP/1.0', | 
| 17 |  |  |  |  |  |  | requests_redirectable => [], | 
| 18 |  |  |  |  |  |  | %{ $_[0]->options }); | 
| 19 |  |  |  |  |  |  | }, | 
| 20 |  |  |  |  |  |  | ); | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub request { | 
| 23 | 0 |  |  | 0 | 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 | 0 |  |  |  |  | if($response->code == 204) { | 
| 30 | 0 |  |  |  |  |  | undef; | 
| 31 |  |  |  |  |  |  | } else { | 
| 32 |  |  |  |  |  |  | eval { | 
| 33 | 0 | 0 |  |  |  |  | $response->content_type eq 'application/json' ? | 
| 34 |  |  |  |  |  |  | decode_json($response->decoded_content) : | 
| 35 |  |  |  |  |  |  | $response; | 
| 36 | 0 | 0 |  |  |  |  | } || do { | 
| 37 | 0 |  |  |  |  |  | $json_err = $@; | 
| 38 |  |  |  |  |  |  | }; | 
| 39 |  |  |  |  |  |  | } | 
| 40 |  |  |  |  |  |  | }; | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 | 0 |  |  |  |  | if($json_err) { | 
|  |  | 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; | 
| 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, L | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | =head1 AUTHOR | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | See L | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | See L | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | =cut | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; |