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