File Coverage

blib/lib/PawsX/DynamoDB/DocumentClient/BatchGet.pm
Criterion Covered Total %
statement 54 56 96.4
branch 6 8 75.0
condition 4 4 100.0
subroutine 13 14 92.8
pod 0 3 0.0
total 77 85 90.5


line stmt bran cond sub pod time code
1             package PawsX::DynamoDB::DocumentClient::BatchGet;
2              
3 1     1   781 use strict;
  1         3  
  1         28  
4 1     1   25 use 5.008_005;
  1         3  
5              
6 1     1   4 use Net::Amazon::DynamoDB::Marshaler;
  1         2  
  1         78  
7 1         41 use PawsX::DynamoDB::DocumentClient::Util qw(
8             make_assert_arrayref
9             make_assert_hashref
10             unmarshal_attribute_map
11 1     1   6 );
  1         2  
12 1     1   427 use PerlX::Maybe;
  1         1453  
  1         544  
13              
14             my $METHOD_NAME = 'batch_get()';
15             my $ASSERT_HASHREF = make_assert_hashref($METHOD_NAME);
16             my $ASSERT_ARRAYREF = make_assert_arrayref($METHOD_NAME);
17              
18             sub transform_arguments {
19 5     5 0 5361 my $class = shift;
20 5         31 my %args = @_;
21 5   100     31 my $force_type = delete $args{force_type} || {};
22             return (
23             %args,
24             RequestItems => _marshall_request_items(
25             $args{RequestItems},
26 5         21 $force_type
27             ),
28             );
29             }
30              
31             sub transform_output {
32 1     1 0 2919 my ($class, $output) = @_;
33 1         29 my $response = $output->Responses;
34             return {
35 1         31 responses => _unmarshall_responses($output->Responses),
36             unprocessed_keys => _unmarshall_unproc_keys($output->UnprocessedKeys),
37             };
38             }
39              
40             sub run_service_command {
41 0     0 0 0 my ($class, $service, %args) = @_;
42 0         0 return $service->BatchGetItem(%args);
43             }
44              
45             sub _marshall_request_items {
46 5     5   24 my ($items, $force_type) = @_;
47 5         22 $ASSERT_HASHREF->('RequestItems', $items);
48             return {
49 4         14 map { $_ => _marshall_request_item($items->{$_}, $force_type->{$_}) }
  5         51  
50             keys %$items
51             };
52             }
53              
54             sub _marshall_request_item {
55 5     5   18 my ($item, $force_type) = @_;
56 5         11 my $keys = $item->{Keys};
57 5   100     23 $force_type ||= {};
58 5 100       22 die "$METHOD_NAME: RequestItems entry must have Keys" unless $keys;
59 4         17 $ASSERT_ARRAYREF->('Keys', $keys);
60             $ASSERT_HASHREF->('Keys entry', $_)
61 3         13 for @$keys;
62             return {
63             %$item,
64             Keys => [
65 3         68 map { dynamodb_marshal($_, force_type => $force_type) }
66 2         7 @{$item->{Keys}}
  2         5  
67             ],
68             };
69             }
70              
71             sub _unmarshall_responses {
72 1     1   10 my ($responses) = @_;
73 1 50       5 return undef unless $responses;
74 1         26 my $tables = $responses->Map;
75             return {
76 1         11 map { $_ => _unmarshall_response_items($tables->{$_}) }
  2         56  
77             keys %$tables
78             };
79             }
80              
81             sub _unmarshall_response_items {
82 2     2   5 my ($items) = @_;
83 2         5 return [ map { unmarshal_attribute_map($_) } @$items ];
  3         39  
84             }
85              
86             sub _unmarshall_unproc_keys {
87 1     1   66 my ($unprocessed) = @_;
88 1         28 my $tables = $unprocessed->Map;
89 1 50       11 return undef unless %$tables;
90             return {
91 1         4 map { $_ => _unmarshall_keys_and_attrs($tables->{$_}) }
  2         30  
92             keys %$tables
93             };
94             }
95              
96             sub _unmarshall_keys_and_attrs {
97 2     2   5 my ($obj) = @_;
98 2         4 my $attr_names;
99 2 100       53 if ($obj->ExpressionAttributeNames) {
100 1         32 $attr_names = $obj->ExpressionAttributeNames->Map;
101             };
102              
103             return {
104             maybe ConsistentRead => $obj->ConsistentRead,
105             maybe ProjectionExpression => $obj->ProjectionExpression,
106             maybe ExpressionAttributeNames => $attr_names,
107             Keys => [
108 2         91 map { unmarshal_attribute_map($_) } @{$obj->Keys}
  3         40  
  2         110  
109             ],
110             }
111             }
112              
113             1;
114             __END__