DocumentClient/Util.pm

filter: Statementstmt 98.7% 81 / 82 Branchbran 93.7% 15 / 16 Conditioncond 66.6% 14 / 21 MC/DCmcdc 36.3% 4 / 11 Subroutinesub 100% 22 / 22 Podpod 0.0% 0 / 7 totaltotal 85.5% 136 / 159 CC 18 SCAR 10.2
CC
18
Cov
92%
__ANON__
5.0
__ANON__
4.1
__ANON__
4.1
CRAP 2.8
« DocumentClient/QueryOrScan.pm ↑ Summary DocumentClient/BatchGet.pm »
1 package PawsX::DynamoDB::DocumentClient::Util;
2  
3 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 our @EXPORT_OK = qw(
8 make_arg_transformer
9 make_attr_map
10 make_attr_name_map
11 make_key
12 make_assert_arrayref
13 make_assert_hashref
14 unmarshal_attribute_map
15 );
16  
17 7 ▶use Net::Amazon::DynamoDB::Marshaler;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 7 ▶use Paws::DynamoDB::AttributeValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 7 ▶use Paws::DynamoDB::AttributeMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 7 ▶use Paws::DynamoDB::ExpressionAttributeNameMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 7 ▶use Paws::DynamoDB::MapAttributeValue;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 7 ▶use Paws::DynamoDB::Key;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶sub make_arg_transformer {
Subroutine make_arg_transformer: called CC=3 SCAR=11.0
Pod undocumented
25 4 my %args = @_;
26 4 ▶ my $method_name = $args{method_name} || die;
Condition50%1/2
$args{'method_name'} || die()
l!l
40
MC/DC0%0/1
$args{'method_name'} || die()
$args{'method_name'}
Truth table50%1/2
A
A= $args{'method_name'}
Aresult
11
00
27 4 ▶ my $to_marshall = $args{to_marshall} || die;
Condition50%1/2
$args{'to_marshall'} || die()
l!l
40
MC/DC0%0/1
$args{'to_marshall'} || die()
$args{'to_marshall'}
Truth table50%1/2
A
A= $args{'to_marshall'}
Aresult
11
00
28 4 my %to_marshall = map { $_ => 1 } @$to_marshall;
29 31 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
30 31 my ($name, $val, $force_type) = @_;
31 31 ▶ return $val unless $to_marshall{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $to_marshall{$name} 12 19 31
32 19 ▶ die "$method_name(): $name must be a hashref"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $val and ref $val eq "HASH" 7 12 19
Condition66%2/3
ref $val and ref $val eq "HASH"
!ll&&!rl&&r
7012
MC/DC50%1/2
ref $val and ref $val eq "HASH"
ref $val ref $val eq "HASH"
Truth table66%2/3
A and B
A= ref $valB= ref $val eq "HASH"
ABresult
0X0
100
111
33 unless ref $val && ref $val eq 'HASH';
34 12 ▶ $force_type ||= {};
Condition100%2/2
$force_type ||= {}
l!l
57
MC/DC100%1/1
$force_type ||= {}
$force_type
Truth table100%2/2
A
A= $force_type
Aresult
11
00
35 12 return dynamodb_marshal($val, force_type => $force_type);
36 4 };
37 }
38  
39 10 ▶sub unmarshal_attribute_map {
Subroutine unmarshal_attribute_map: called CC=1 SCAR=0.0
Pod undocumented
40 10 my ($map) = @_;
41 10 my $plain_vals = _translate_attr_map($map->Map);
42 10 return dynamodb_unmarshal($plain_vals);
43 }
44  
45 7 ▶sub make_attr_map {
Subroutine make_attr_map: called CC=1 SCAR=0.0
Pod undocumented
46 7 my ($attrs) = @_;
47 7 my %map = map { $_ => _make_attr_val($attrs->{$_}) } keys %$attrs;
48 7 return Paws::DynamoDB::AttributeMap->new(Map => \%map);
49 }
50  
51 3 ▶sub make_key {
Subroutine make_key: called CC=1 SCAR=0.0
Pod undocumented
52 3 my ($val) = @_;
53 3 my %map = map { $_ => _make_attr_val($val->{$_}) } keys %$val;
54 3 return Paws::DynamoDB::Key->new(
55 Map => \%map
56 );
57 }
58  
59 1 ▶sub make_attr_name_map {
Subroutine make_attr_name_map: called CC=1 SCAR=0.0
Pod undocumented
60 1 my ($names) = @_;
61 1 return Paws::DynamoDB::ExpressionAttributeNameMap->new(
62 Map => $names,
63 );
64 }
65  
66 1 ▶sub make_assert_arrayref {
Subroutine make_assert_arrayref: called CC=1 SCAR=0.0
Pod undocumented
67 1 my ($prefix) = @_;
68 4 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
69 4 my ($label, $val) = @_;
70 4 ▶ die "$prefix: $label must be an arrayref" unless (
Branch: 1 branch
BranchTrueFalseTotal
unless $val and ref $val and ref $val eq "ARRAY" 1 3 4
Condition66%4/6
$val and ref $val and ref $val eq "ARRAY"
!ll&&!rl&&r
103
$val and ref $val
!ll&&!rl&&r
013
MC/DC33%1/3
$val and ref $val and ref $val eq "ARRAY"
$val ref $val ref $val eq "ARRAY"
Truth table50%2/4
A and B and C
A= $valB= ref $valC= ref $val eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
71 $val
72 && ref $val
73 && ref $val eq 'ARRAY'
74 );
75 }
76 1 }
77  
78 1 ▶sub make_assert_hashref {
Subroutine make_assert_hashref: called CC=1 SCAR=0.0
Pod undocumented
79 1 my ($prefix) = @_;
80 9 ▶ return sub {
Subroutine __ANON__: called CC=4 SCAR=14.2
81 9 my ($label, $val) = @_;
82 9 ▶ die "$prefix: $label must be a hashref" unless (
Branch: 1 branch
BranchTrueFalseTotal
unless $val and ref $val and ref $val eq "HASH" 2 7 9
Condition66%4/6
$val and ref $val and ref $val eq "HASH"
!ll&&!rl&&r
207
$val and ref $val
!ll&&!rl&&r
027
MC/DC33%1/3
$val and ref $val and ref $val eq "HASH"
$val ref $val ref $val eq "HASH"
Truth table50%2/4
A and B and C
A= $valB= ref $valC= ref $val eq "HASH"
ABCresult
0XX0
10X0
1100
1111
83 $val
84 && ref $val
85 && ref $val eq 'HASH'
86 );
87 }
88 1 }
89  
90 11 ▶sub _translate_attr_map {
Subroutine _translate_attr_map: called CC=1 SCAR=0.0
91 11 my ($map) = @_;
92 11 return { map { $_ => _translate_attr_val($map->{$_}) } keys %$map };
93 }
94  
95 23 ▶sub _translate_attr_val {
Subroutine _translate_attr_val: called CC=4 SCAR=14.0
96 23 my ($attr_val) = @_;
97 23 return { $_ => $attr_val->$_ } for grep { defined $attr_val->$_ }
98 qw(NULL S N BOOL B BS NS SS);
99 2 ▶ return { M => _translate_attr_map($attr_val->M->Map) }
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr_val->M 1 1 2
100 if defined $attr_val->M;
101 1 ▶ return { L => [ map { _translate_attr_val($_) } @{ $attr_val->L } ] }
Branch: 1 branch
BranchTrueFalseTotal
if defined $attr_val->L 1 0 1
102 if defined $attr_val->L;
103 0 die 'unable to extract value out of Paws::DynamoDB::AttributeValue object!';
104 }
105  
106 23 ▶sub _make_attr_val {
Subroutine _make_attr_val: called CC=3 SCAR=11.0
107 23 my ($type_and_val) = @_;
108 23 my ($type, $val) = %$type_and_val;
109 23 ▶ if ($type eq 'L') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "L") 1 22 23
110 1 my @list = map { _make_attr_val($_) } @$val;
111 1 return Paws::DynamoDB::AttributeValue->new(
112 L => \@list,
113 );
114 }
115 22 ▶ if ($type eq 'M') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "M") 1 21 22
116 1 my %map = map { $_ => _make_attr_val($val->{$_}) } keys %$val;
117 1 return Paws::DynamoDB::AttributeValue->new(
118 M => Paws::DynamoDB::MapAttributeValue->new(
119 Map => \%map,
120 ),
121 );
122 }
123 21 return Paws::DynamoDB::AttributeValue->new(
124 L => [], # Paws always returns an empty list
125 $type => $val,
126 );
127 }
128  
129 7 1;
130 __END__
« DocumentClient/QueryOrScan.pm ↑ Summary DocumentClient/BatchGet.pm »