| 1 | package Amazon::DynamoDB::MojoUA; | ||
| 2 | $Amazon::DynamoDB::MojoUA::VERSION = '0.35'; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | |||
| 7 | use Future; | ||
| 8 | use Mojo::UserAgent; | ||
| 9 | |||
| 10 | |||
| 11 | sub new { my $class = shift; bless {@_}, $class } | ||
| 12 | |||
| 13 | |||
| 14 | sub request { | ||
| 15 | my $self = shift; | ||
| 16 | my $req = shift; | ||
| 17 | my $method = lc $req->method; | ||
| 18 | my $tx = $self->ua->$method(''.$req->uri => { map {; $_ => ''.$req->header($_) } $req->header_field_names } => $req->content); | ||
| 19 | if(my $res = $tx->success) { | ||
| 20 | return Future->new->done($res->body) | ||
| 21 | } | ||
| 22 | |||
| 23 | my $status = $tx->res->code; | ||
| 24 | return Future->new->fail($status, $tx->res, $req) | ||
| 25 | } | ||
| 26 | |||
| 27 | |||
| 28 | sub ua { shift->{ua} ||= Mojo::UserAgent->new } | ||
| 29 | |||
| 30 | 1; | ||
| 31 | |||
| 32 | __END__ |