| 1 | package WebService::OANDA::ExchangeRates::Response; | ||||||||||
| 2 | |||||||||||
| 3 | 5 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use HTTP::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use JSON::XS qw{decode_json}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 5 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 5 | has http_response => ( | |||||||||
| 10 | is => 'rw', | ||||||||||
| 11 | handles => { | ||||||||||
| 12 | is_success => 'is_success', | ||||||||||
| 13 | is_error => 'is_error', | ||||||||||
| 14 | raw_data => 'content', | ||||||||||
| 15 | http_status => 'code', | ||||||||||
| 16 | }, | ||||||||||
| 17 | required => 1, | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 5 | has data => ( is => 'rw' ); | |||||||||
| 21 | |||||||||||
| 22 | 4 | ▶ | sub BUILD { | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=1.2
Pod
undocumented
| |||||||||||
| 23 | 4 | my $self = shift; | |||||||||
| 24 | 4 | my $data; | |||||||||
| 25 | |||||||||||
| 26 | 4 | ▶ | try { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 4 | $data = JSON::XS::decode_json( $self->raw_data ); | |||||||||
| 28 | } | ||||||||||
| 29 | 0 | ▶ | catch { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 30 | 0 | $data = { | |||||||||
| 31 | code => undef, | ||||||||||
| 32 | message => sprintf( | ||||||||||
| 33 | 'Failed to decode content(%s): $%s', $self->raw_data, $_ | ||||||||||
| 34 | ) | ||||||||||
| 35 | }; | ||||||||||
| 36 | |||||||||||
| 37 | # if we failed to decode the json on a successful query, we'll consider | ||||||||||
| 38 | # this an outlier and force a 500 | ||||||||||
| 39 | 0 | ▶ | if ($self->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 0 | $self->http_response( | |||||||||
| 41 | HTTP::Response->new(500, undef, undef, $self->raw_data) | ||||||||||
| 42 | ); | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 4 | }; | |||||||||
| 46 | |||||||||||
| 47 | 4 | $self->data($data); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | ▶ | sub error_message { | ||||||||
|
Subroutine
error_message: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 51 | 0 | my $self = shift; | |||||||||
| 52 | |||||||||||
| 53 | 0 | ▶ | return unless $self->is_error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | return $self->data->{message}; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub error_code { | ||||||||
|
Subroutine
error_code: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 58 | 0 | my $self = shift; | |||||||||
| 59 | 0 | ▶ | return unless $self->is_error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | return $self->data->{code}; | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 5 | 1; | |||||||||
| 64 | |||||||||||
| 65 | __END__ | ||||||||||