line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PawsX::DynamoDB::DocumentClient::BatchWrite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
765
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
24
|
use 5.008_005; |
|
1
|
|
|
|
|
3
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Net::Amazon::DynamoDB::Marshaler; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
53
|
|
7
|
1
|
|
|
|
|
576
|
use PawsX::DynamoDB::DocumentClient::Util qw( |
8
|
|
|
|
|
|
|
make_assert_arrayref |
9
|
|
|
|
|
|
|
make_assert_hashref |
10
|
|
|
|
|
|
|
unmarshal_attribute_map |
11
|
1
|
|
|
1
|
|
5
|
); |
|
1
|
|
|
|
|
2
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $METHOD_NAME = 'batch_write()'; |
14
|
|
|
|
|
|
|
my $ASSERT_HASHREF = make_assert_hashref($METHOD_NAME); |
15
|
|
|
|
|
|
|
my $ASSERT_ARRAYREF = make_assert_arrayref($METHOD_NAME); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub transform_arguments { |
18
|
12
|
|
|
12
|
0
|
15007
|
my $class = shift; |
19
|
12
|
|
|
|
|
39
|
my %args = @_; |
20
|
12
|
|
100
|
|
|
63
|
my $force_type = delete $args{force_type} || {}; |
21
|
|
|
|
|
|
|
return ( |
22
|
|
|
|
|
|
|
%args, |
23
|
|
|
|
|
|
|
RequestItems => _marshall_request_items( |
24
|
|
|
|
|
|
|
$args{RequestItems}, |
25
|
12
|
|
|
|
|
45
|
$force_type |
26
|
|
|
|
|
|
|
), |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub transform_output { |
31
|
1
|
|
|
1
|
0
|
3519
|
my ($class, $output) = @_; |
32
|
1
|
|
|
|
|
37
|
my $tables = $output->UnprocessedItems->Map; |
33
|
1
|
50
|
|
|
|
47
|
return undef unless %$tables; |
34
|
|
|
|
|
|
|
return { |
35
|
1
|
|
|
|
|
5
|
map { $_ => _unmarshall_requests($tables->{$_}) } |
|
2
|
|
|
|
|
50
|
|
36
|
|
|
|
|
|
|
keys %$tables |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub run_service_command { |
41
|
0
|
|
|
0
|
0
|
0
|
my ($class, $service, %args) = @_; |
42
|
0
|
|
|
|
|
0
|
return $service->BatchWriteItem(%args); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _marshall_request_items { |
46
|
12
|
|
|
12
|
|
26
|
my ($tables, $force_type) = @_; |
47
|
12
|
|
|
|
|
53
|
$ASSERT_HASHREF->('RequestItems', $tables); |
48
|
|
|
|
|
|
|
return { |
49
|
|
|
|
|
|
|
map { |
50
|
11
|
|
|
|
|
39
|
$_ => _marshall_request_items_list( |
51
|
|
|
|
|
|
|
$tables->{$_}, |
52
|
13
|
|
|
|
|
184
|
$force_type->{$_} |
53
|
|
|
|
|
|
|
) |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
keys %$tables |
56
|
|
|
|
|
|
|
}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _marshall_request_items_list { |
60
|
13
|
|
|
13
|
|
36
|
my ($requests, $force_type) = @_; |
61
|
13
|
|
|
|
|
48
|
$ASSERT_ARRAYREF->('RequestItems value', $requests); |
62
|
|
|
|
|
|
|
return [ |
63
|
12
|
|
|
|
|
28
|
map { _marshall_request($_, $force_type) } |
|
15
|
|
|
|
|
528
|
|
64
|
|
|
|
|
|
|
@$requests |
65
|
|
|
|
|
|
|
]; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _marshall_request { |
69
|
15
|
|
|
15
|
|
37
|
my ($request, $force_type) = @_; |
70
|
15
|
|
|
|
|
62
|
$ASSERT_HASHREF->('write request', $request); |
71
|
14
|
|
|
|
|
30
|
my $put_request = $request->{PutRequest}; |
72
|
14
|
|
|
|
|
57
|
my $delete_request = $request->{DeleteRequest}; |
73
|
|
|
|
|
|
|
|
74
|
14
|
100
|
100
|
|
|
69
|
die "$METHOD_NAME: write request missing PutRequest or DeleteRequest" |
75
|
|
|
|
|
|
|
unless ($put_request || $delete_request); |
76
|
|
|
|
|
|
|
|
77
|
13
|
100
|
|
|
|
44
|
return _marshall_put_request($put_request, $force_type) if $put_request; |
78
|
5
|
|
|
|
|
16
|
return _marshall_delete_request($delete_request, $force_type); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub _marshall_put_request { |
82
|
8
|
|
|
8
|
|
18
|
my ($val, $force_type) = @_; |
83
|
8
|
|
|
|
|
30
|
$ASSERT_HASHREF->('PutRequest', $val); |
84
|
7
|
|
|
|
|
19
|
my $item = $val->{Item}; |
85
|
7
|
100
|
|
|
|
29
|
die "$METHOD_NAME: PutRequest must contain Item" unless $item; |
86
|
6
|
|
|
|
|
22
|
$ASSERT_HASHREF->(q|PutRequest's Item|, $item); |
87
|
|
|
|
|
|
|
return { |
88
|
5
|
|
|
|
|
22
|
PutRequest => { |
89
|
|
|
|
|
|
|
Item => dynamodb_marshal($item, force_type => $force_type), |
90
|
|
|
|
|
|
|
}, |
91
|
|
|
|
|
|
|
}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub _marshall_delete_request { |
95
|
5
|
|
|
5
|
|
13
|
my ($val, $force_type) = @_; |
96
|
5
|
|
|
|
|
18
|
$ASSERT_HASHREF->(q|DeleteRequest|, $val); |
97
|
4
|
|
|
|
|
10
|
my $key = $val->{Key}; |
98
|
4
|
100
|
|
|
|
21
|
die "$METHOD_NAME: DeleteRequest must contain Key" unless $key; |
99
|
3
|
|
|
|
|
12
|
$ASSERT_HASHREF->(q|DeleteRequest's Key|, $key); |
100
|
|
|
|
|
|
|
return { |
101
|
2
|
|
|
|
|
8
|
DeleteRequest => { |
102
|
|
|
|
|
|
|
Key => dynamodb_marshal($key, force_type => $force_type), |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _unmarshall_requests { |
108
|
2
|
|
|
2
|
|
5
|
my ($requests) = @_; |
109
|
2
|
|
|
|
|
4
|
return [ map { _unmarshall_request($_) } @$requests ]; |
|
3
|
|
|
|
|
40
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub _unmarshall_request { |
113
|
3
|
|
|
3
|
|
8
|
my ($request) = @_; |
114
|
3
|
100
|
|
|
|
72
|
return $request->PutRequest |
115
|
|
|
|
|
|
|
? _unmarshall_put_request($request->PutRequest) |
116
|
|
|
|
|
|
|
: _unmarshall_delete_request($request->DeleteRequest); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _unmarshall_put_request { |
120
|
2
|
|
|
2
|
|
84
|
my ($request) = @_; |
121
|
|
|
|
|
|
|
return { |
122
|
2
|
|
|
|
|
46
|
PutRequest => { |
123
|
|
|
|
|
|
|
Item => unmarshal_attribute_map($request->Item), |
124
|
|
|
|
|
|
|
}, |
125
|
|
|
|
|
|
|
}; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _unmarshall_delete_request { |
129
|
1
|
|
|
1
|
|
41
|
my ($request) = @_; |
130
|
|
|
|
|
|
|
return { |
131
|
1
|
|
|
|
|
71
|
DeleteRequest => { |
132
|
|
|
|
|
|
|
Key => unmarshal_attribute_map($request->Key), |
133
|
|
|
|
|
|
|
}, |
134
|
|
|
|
|
|
|
}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |
138
|
|
|
|
|
|
|
__END__ |