| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::ORCID::Transport::LWP; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 88697 | use strict; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 4 | 1 |  |  | 1 |  | 10 | use warnings; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 56 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = 0.02_01; | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 598 | use LWP::UserAgent (); | 
|  | 1 |  |  |  |  | 46116 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 9 | 1 |  |  | 1 |  | 571 | use Moo; | 
|  | 1 |  |  |  |  | 10765 |  | 
|  | 1 |  |  |  |  | 4 |  | 
| 10 | 1 |  |  | 1 |  | 1439 | use namespace::clean; | 
|  | 1 |  |  |  |  | 8972 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | with 'WWW::ORCID::Transport'; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | has _client => | 
| 15 |  |  |  |  |  |  | (is => 'ro', init_arg => 0, lazy => 1, builder => '_build_client',); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub _build_client { | 
| 18 | 0 |  |  | 0 |  |  | LWP::UserAgent->new; | 
| 19 |  |  |  |  |  |  | } | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | sub get { | 
| 22 |  |  |  |  |  |  | my ($self, $url, $params, $headers) = @_; | 
| 23 |  |  |  |  |  |  | $url = $self->_param_url($url, $params) if $params; | 
| 24 |  |  |  |  |  |  | my $res = $self->_client->get($url, %$headers); | 
| 25 |  |  |  |  |  |  | [$res->code, $self->_get_headers($res), $res->content]; | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub post_form { | 
| 29 |  |  |  |  |  |  | my ($self, $url, $form, $headers) = @_; | 
| 30 |  |  |  |  |  |  | my $res = $self->_client->post($url, $form, %$headers); | 
| 31 |  |  |  |  |  |  | [$res->code, $self->_get_headers($res), $res->content]; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub post { | 
| 35 |  |  |  |  |  |  | my ($self, $url, $body, $headers) = @_; | 
| 36 |  |  |  |  |  |  | my $res = $self->_client->post($url, %$headers, Content => $body); | 
| 37 |  |  |  |  |  |  | [$res->code, $self->_get_headers($res), $res->content]; | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub put { | 
| 41 |  |  |  |  |  |  | my ($self, $url, $body, $headers) = @_; | 
| 42 |  |  |  |  |  |  | my $res = $self->_client->put($url, %$headers, Content => $body); | 
| 43 |  |  |  |  |  |  | [$res->code, $self->_get_headers($res), $res->content]; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | sub delete { | 
| 47 |  |  |  |  |  |  | my ($self, $url, $params, $headers) = @_; | 
| 48 |  |  |  |  |  |  | $url = $self->_param_url($url, $params) if $params; | 
| 49 |  |  |  |  |  |  | my $res = $self->_client->delete($url, %$headers); | 
| 50 |  |  |  |  |  |  | [$res->code, $self->_get_headers($res), $res->content]; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | sub _get_headers { | 
| 54 | 0 |  |  | 0 |  |  | my ($self, $msg) = @_; | 
| 55 | 0 |  |  |  |  |  | my $headers = {}; | 
| 56 | 0 |  |  |  |  |  | for my $key ($msg->header_field_names) { | 
| 57 | 0 |  |  |  |  |  | $headers->{lc $key} = $msg->header($key); | 
| 58 |  |  |  |  |  |  | } | 
| 59 | 0 |  |  |  |  |  | $headers; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | 1; |