| 1 | package Net::Amazon::DynamoDB::Lite; | ||||||||||||||
| 2 | 16 | ▶ | use 5.008001; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 16 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 16 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 16 | our $VERSION = "0.03"; | |||||||||||||
| 7 | |||||||||||||||
| 8 | 16 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 16 | ▶ | use Furl; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 16 | ▶ | use HTTP::Request; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 16 | ▶ | use JSON; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 16 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 16 | ▶ | use POSIX qw(setlocale LC_TIME strftime); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 16 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 16 | ▶ | use WebService::Amazon::Signature::v4; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 16 | has signature => ( | |||||||||||||
| 18 | is => 'lazy', | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 16 | has scope => ( | |||||||||||||
| 22 | is => 'lazy', | ||||||||||||||
| 23 | ); | ||||||||||||||
| 24 | |||||||||||||||
| 25 | 16 | has ua => ( | |||||||||||||
| 26 | is => 'lazy', | ||||||||||||||
| 27 | ); | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 16 | has uri => ( | |||||||||||||
| 30 | is => 'lazy', | ||||||||||||||
| 31 | ); | ||||||||||||||
| 32 | |||||||||||||||
| 33 | 16 | has access_key => ( | |||||||||||||
| 34 | is => 'ro', | ||||||||||||||
| 35 | ); | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 16 | has secret_key => ( | |||||||||||||
| 38 | is => 'ro', | ||||||||||||||
| 39 | ); | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 16 | has region => ( | |||||||||||||
| 42 | is => 'ro', | ||||||||||||||
| 43 | ); | ||||||||||||||
| 44 | |||||||||||||||
| 45 | has api_version => ( | ||||||||||||||
| 46 | is => 'ro', | ||||||||||||||
| 47 | default => sub { | ||||||||||||||
| 48 | 15 | ▶ | '20120810', | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 49 | }, | ||||||||||||||
| 50 | 16 | ); | |||||||||||||
| 51 | |||||||||||||||
| 52 | has ca_path => ( | ||||||||||||||
| 53 | is => 'rw', | ||||||||||||||
| 54 | default => sub { | ||||||||||||||
| 55 | 15 | ▶ | '/etc/ssl/certs', | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 56 | }, | ||||||||||||||
| 57 | 16 | ); | |||||||||||||
| 58 | |||||||||||||||
| 59 | has connection_timeout => ( | ||||||||||||||
| 60 | is => 'rw', | ||||||||||||||
| 61 | default => sub { | ||||||||||||||
| 62 | 15 | ▶ | 1, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 63 | }, | ||||||||||||||
| 64 | 16 | ); | |||||||||||||
| 65 | |||||||||||||||
| 66 | has json => ( | ||||||||||||||
| 67 | is => 'rw', | ||||||||||||||
| 68 | default => sub { | ||||||||||||||
| 69 | 15 | ▶ | JSON->new, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 70 | }, | ||||||||||||||
| 71 | 16 | ); | |||||||||||||
| 72 | |||||||||||||||
| 73 | sub _build_signature { | ||||||||||||||
| 74 | 15 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
_build_signature: called CC=1 SCAR=0.0
| |||||||||||||||
| 75 | 15 | my $locale = setlocale(LC_TIME); | |||||||||||||
| 76 | 15 | setlocale(LC_TIME, "C"); | |||||||||||||
| 77 | 15 | my $v4 = WebService::Amazon::Signature::v4->new( | |||||||||||||
| 78 | scope => $self->scope, | ||||||||||||||
| 79 | access_key => $self->access_key, | ||||||||||||||
| 80 | secret_key => $self->secret_key, | ||||||||||||||
| 81 | ); | ||||||||||||||
| 82 | 15 | setlocale(LC_TIME, $locale); | |||||||||||||
| 83 | 15 | $v4; | |||||||||||||
| 84 | } | ||||||||||||||
| 85 | |||||||||||||||
| 86 | sub _build_scope { | ||||||||||||||
| 87 | 15 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
_build_scope: called CC=1 SCAR=0.0
| |||||||||||||||
| 88 | 15 | join '/', strftime('%Y%m%d', gmtime), $self->region, qw(dynamodb aws4_request); | |||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | sub _build_ua { | ||||||||||||||
| 92 | 13 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
_build_ua: called CC=1 SCAR=0.0
| |||||||||||||||
| 93 | |||||||||||||||
| 94 | 13 | my $ua = Furl->new( | |||||||||||||
| 95 | agent => 'Net::Amazon::DynamoDB::Lite ' . $VERSION, | ||||||||||||||
| 96 | timeout => $self->connection_timeout, | ||||||||||||||
| 97 | ssl_opts => { | ||||||||||||||
| 98 | SSL_ca_path => $self->ca_path, | ||||||||||||||
| 99 | }, | ||||||||||||||
| 100 | ); | ||||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | sub _build_uri { | ||||||||||||||
| 104 | 2 | ▶ | my ($self) = @_; | ||||||||||||
|
Subroutine
_build_uri: called CC=1 SCAR=0.0
| |||||||||||||||
| 105 | 2 | URI->new('https://dynamodb.' . $self->region . '.amazonaws.com/'); | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | sub make_request { | ||||||||||||||
| 109 | 14 | ▶ | my ($self, $target, $content) = @_; | ||||||||||||
|
Subroutine
make_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 110 | |||||||||||||||
| 111 | 14 | my $req = HTTP::Request->new( | |||||||||||||
| 112 | POST => $self->uri, | ||||||||||||||
| 113 | ); | ||||||||||||||
| 114 | 14 | my $locale = setlocale(LC_TIME); | |||||||||||||
| 115 | 14 | setlocale(LC_TIME, "C"); | |||||||||||||
| 116 | 14 | $req->header(host => $self->uri->host); | |||||||||||||
| 117 | 14 | my $http_date = strftime('%a, %d %b %Y %H:%M:%S %Z', localtime); | |||||||||||||
| 118 | 14 | my $amz_date = strftime('%Y%m%dT%H%M%SZ', gmtime); | |||||||||||||
| 119 | 14 | $req->header(Date => $http_date); | |||||||||||||
| 120 | 14 | $req->header('x-amz-date' => $amz_date); | |||||||||||||
| 121 | 14 | $req->header('x-amz-target' => 'DynamoDB_' . $self->api_version . ".$target" ); | |||||||||||||
| 122 | 14 | $req->header('content-type' => 'application/x-amz-json-1.0'); | |||||||||||||
| 123 | 14 | $content = $self->json->encode($content); | |||||||||||||
| 124 | 14 | $req->content($content); | |||||||||||||
| 125 | 14 | $req->header('Content-Length' => length($content)); | |||||||||||||
| 126 | 14 | $self->signature->from_http_request($req); | |||||||||||||
| 127 | 14 | $req->header(Authorization => $self->signature->calculate_signature); | |||||||||||||
| 128 | 14 | setlocale(LC_TIME, $locale); | |||||||||||||
| 129 | 14 | return $req; | |||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | sub list_tables { | ||||||||||||||
| 133 | 13 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
list_tables: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||
| 134 | |||||||||||||||
| 135 | 13 | ▶ | $content = {} unless $content; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 136 | 13 | my $req = $self->make_request('ListTables', $content); | |||||||||||||
| 137 | 13 | my $res = $self->ua->request($req); | |||||||||||||
| 138 | 13 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 139 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 140 | 0 | return $decoded->{TableNames}; | |||||||||||||
| 141 | } | ||||||||||||||
| 142 | else { | ||||||||||||||
| 143 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 144 | } | ||||||||||||||
| 145 | } | ||||||||||||||
| 146 | |||||||||||||||
| 147 | sub put_item { | ||||||||||||||
| 148 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
put_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 149 | |||||||||||||||
| 150 | 0 | ▶ | Carp::croak "Item required." unless $content->{Item}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 151 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 152 | 0 | my $req = $self->make_request('PutItem', $content); | |||||||||||||
| 153 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 154 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 155 | 0 | return 1; | |||||||||||||
| 156 | } else { | ||||||||||||||
| 157 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 158 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 159 | } | ||||||||||||||
| 160 | } | ||||||||||||||
| 161 | |||||||||||||||
| 162 | sub get_item { | ||||||||||||||
| 163 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
get_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 164 | |||||||||||||||
| 165 | 0 | ▶ | Carp::croak "Key required." unless $content->{Key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 166 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 167 | 0 | my $req = $self->make_request('GetItem', $content); | |||||||||||||
| 168 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 169 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 170 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 171 | 0 | return _except_type($decoded->{Item}); | |||||||||||||
| 172 | } | ||||||||||||||
| 173 | else { | ||||||||||||||
| 174 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 175 | } | ||||||||||||||
| 176 | |||||||||||||||
| 177 | } | ||||||||||||||
| 178 | |||||||||||||||
| 179 | sub update_item { | ||||||||||||||
| 180 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
update_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 181 | |||||||||||||||
| 182 | 0 | ▶ | Carp::croak "Key required." unless $content->{Key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 183 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 184 | 0 | my $req = $self->make_request('UpdateItem', $content); | |||||||||||||
| 185 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 186 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 187 | 0 | return 1; | |||||||||||||
| 188 | } else { | ||||||||||||||
| 189 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 190 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 191 | } | ||||||||||||||
| 192 | } | ||||||||||||||
| 193 | |||||||||||||||
| 194 | sub delete_item { | ||||||||||||||
| 195 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
delete_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 196 | |||||||||||||||
| 197 | 0 | ▶ | Carp::croak "Key required." unless $content->{Key}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 198 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 199 | 0 | my $req = $self->make_request('DeleteItem', $content); | |||||||||||||
| 200 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 201 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 202 | 0 | return 1; | |||||||||||||
| 203 | } else { | ||||||||||||||
| 204 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 205 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 206 | } | ||||||||||||||
| 207 | } | ||||||||||||||
| 208 | |||||||||||||||
| 209 | sub create_table { | ||||||||||||||
| 210 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
create_table: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||
| 211 | |||||||||||||||
| 212 | 0 | ▶ | Carp::croak "AttributeDefinitions required." unless $content->{AttributeDefinitions}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 213 | 0 | ▶ | Carp::croak "KeySchema required." unless $content->{KeySchema}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 214 | 0 | ▶ | Carp::croak "ProvisionedThroughput required." unless $content->{ProvisionedThroughput}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 215 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 216 | |||||||||||||||
| 217 | 0 | my $req = $self->make_request('CreateTable', $content); | |||||||||||||
| 218 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 219 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 220 | 0 | return 1; | |||||||||||||
| 221 | } else { | ||||||||||||||
| 222 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 223 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 224 | } | ||||||||||||||
| 225 | } | ||||||||||||||
| 226 | |||||||||||||||
| 227 | sub delete_table { | ||||||||||||||
| 228 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
delete_table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 229 | |||||||||||||||
| 230 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 231 | 0 | my $req = $self->make_request('DeleteTable', $content); | |||||||||||||
| 232 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 233 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 234 | 0 | return 1; | |||||||||||||
| 235 | } else { | ||||||||||||||
| 236 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 237 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 238 | } | ||||||||||||||
| 239 | } | ||||||||||||||
| 240 | |||||||||||||||
| 241 | sub describe_table { | ||||||||||||||
| 242 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
describe_table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 243 | |||||||||||||||
| 244 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 245 | 0 | my $req = $self->make_request('DescribeTable', $content); | |||||||||||||
| 246 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 247 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 248 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 249 | 0 | return $decoded->{Table}; | |||||||||||||
| 250 | } | ||||||||||||||
| 251 | else { | ||||||||||||||
| 252 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 253 | } | ||||||||||||||
| 254 | |||||||||||||||
| 255 | } | ||||||||||||||
| 256 | |||||||||||||||
| 257 | sub update_table { | ||||||||||||||
| 258 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
update_table: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 259 | |||||||||||||||
| 260 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 261 | 0 | my $req = $self->make_request('UpdateTable', $content); | |||||||||||||
| 262 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 263 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 264 | 0 | return 1; | |||||||||||||
| 265 | } else { | ||||||||||||||
| 266 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 267 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 268 | } | ||||||||||||||
| 269 | } | ||||||||||||||
| 270 | |||||||||||||||
| 271 | sub query { | ||||||||||||||
| 272 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
query: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 273 | |||||||||||||||
| 274 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 275 | 0 | my $req = $self->make_request('Query', $content); | |||||||||||||
| 276 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 277 | |||||||||||||||
| 278 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 279 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 280 | 0 | return _except_type($decoded->{Items}); | |||||||||||||
| 281 | } else { | ||||||||||||||
| 282 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 283 | } | ||||||||||||||
| 284 | } | ||||||||||||||
| 285 | |||||||||||||||
| 286 | sub scan { | ||||||||||||||
| 287 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
scan: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 288 | |||||||||||||||
| 289 | 0 | ▶ | Carp::croak "TableName required." unless $content->{TableName}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 290 | 0 | my $req = $self->make_request('Scan', $content); | |||||||||||||
| 291 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 292 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 293 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 294 | 0 | return _except_type($decoded->{Items}); | |||||||||||||
| 295 | } else { | ||||||||||||||
| 296 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 297 | } | ||||||||||||||
| 298 | } | ||||||||||||||
| 299 | |||||||||||||||
| 300 | sub batch_get_item { | ||||||||||||||
| 301 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
batch_get_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||
| 302 | |||||||||||||||
| 303 | 0 | ▶ | Carp::croak "RequestItems required." unless $content->{RequestItems}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 304 | 0 | my $req = $self->make_request('BatchGetItem', $content); | |||||||||||||
| 305 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 306 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 307 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 308 | 0 | my $res; | |||||||||||||
| 309 | 0 | for my $k (keys %{$decoded->{Responses}}) { | |||||||||||||
| 310 | 0 | push @{$res}, {$k => _except_type($decoded->{Responses}->{$k})}; | |||||||||||||
| 311 | } | ||||||||||||||
| 312 | 0 | return $res; | |||||||||||||
| 313 | } else { | ||||||||||||||
| 314 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 315 | } | ||||||||||||||
| 316 | } | ||||||||||||||
| 317 | |||||||||||||||
| 318 | sub batch_write_item { | ||||||||||||||
| 319 | 0 | ▶ | my ($self, $content) = @_; | ||||||||||||
|
Subroutine
batch_write_item: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||
| 320 | |||||||||||||||
| 321 | 0 | ▶ | Carp::croak "RequestItems required." unless $content->{RequestItems}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 322 | 0 | my $req = $self->make_request('BatchWriteItem', $content); | |||||||||||||
| 323 | 0 | my $res = $self->ua->request($req); | |||||||||||||
| 324 | 0 | ▶ | if ($res->is_success) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 325 | 0 | return 1; | |||||||||||||
| 326 | } | ||||||||||||||
| 327 | else { | ||||||||||||||
| 328 | 0 | my $decoded = $self->json->decode($res->content); | |||||||||||||
| 329 | 0 | Carp::croak $self->_error_content($res, $decoded); | |||||||||||||
| 330 | } | ||||||||||||||
| 331 | } | ||||||||||||||
| 332 | |||||||||||||||
| 333 | sub _except_type { | ||||||||||||||
| 334 | 0 | ▶ | my $v = shift; | ||||||||||||
|
Subroutine
_except_type: not called CC=6 SCAR=37.4
| |||||||||||||||
| 335 | 0 | my $res; | |||||||||||||
| 336 | 0 | ▶ | if (ref $v eq 'HASH') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 337 | 0 | for my $k (keys %{$v}) { | |||||||||||||
| 338 | 0 | my $with_type = $v->{$k}; | |||||||||||||
| 339 | 0 | my ($k2) = keys %{$with_type}; | |||||||||||||
| 340 | 0 | $res->{$k} = $with_type->{$k2}; | |||||||||||||
| 341 | } | ||||||||||||||
| 342 | } elsif (ref $v eq 'ARRAY') { | ||||||||||||||
| 343 | 0 | for my $w (@{$v}) { | |||||||||||||
| 344 | 0 | my $with_out_type; | |||||||||||||
| 345 | 0 | for my $k (keys %{$w}) { | |||||||||||||
| 346 | 0 | my $with_type = $w->{$k}; | |||||||||||||
| 347 | 0 | my ($k2) = keys %{$with_type}; | |||||||||||||
| 348 | 0 | $with_out_type->{$k} = $with_type->{$k2}; | |||||||||||||
| 349 | } | ||||||||||||||
| 350 | 0 | push @{$res}, $with_out_type; | |||||||||||||
| 351 | } | ||||||||||||||
| 352 | } | ||||||||||||||
| 353 | 0 | return $res; | |||||||||||||
| 354 | } | ||||||||||||||
| 355 | |||||||||||||||
| 356 | sub _error_content { | ||||||||||||||
| 357 | 0 | ▶ | my ($self, $res, $decoded) = @_; | ||||||||||||
|
Subroutine
_error_content: not called CC=2 SCAR=17.9
| |||||||||||||||
| 358 | |||||||||||||||
| 359 | 0 | ▶ | my $message = $decoded->{Message} ? $decoded->{Message} : $decoded->{message}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 360 | return "status_code : " . $res->status_line | ||||||||||||||
| 361 | . " __type : " . $decoded->{__type} | ||||||||||||||
| 362 | 0 | . " message : " . $message; | |||||||||||||
| 363 | } | ||||||||||||||
| 364 | |||||||||||||||
| 365 | |||||||||||||||
| 366 | 16 | 1; | |||||||||||||
| 367 | __END__ | ||||||||||||||