blib/lib/MooseX/Storage/IO/AmazonDynamoDB.pm

filter: Statementstmt 50.0% 35 / 70 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 56.2% 9 / 16 Podpod n/a totaltotal 40.0% 44 / 110 CC 9 SCAR 29.2
CC
9
Cov
40%
__ANON__
56.0
__ANON__
12.0
__ANON__
2.0
CRAP 18.6
↑ Summary
1 package MooseX::Storage::IO::AmazonDynamoDB;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 our $VERSION = '0.08';
6  
7 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use JSON::MaybeXS;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use MooseX::Storage;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use PawsX::DynamoDB::DocumentClient;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Types::Standard qw(HasMethods);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 parameter key_attr => (
16 isa => 'Str',
17 required => 1,
18 );
19  
20 1 parameter table_name => (
21 isa => 'Maybe[Str]',
22 default => undef,
23 );
24  
25 1 parameter table_name_method => (
26 isa => 'Str',
27 default => 'dynamo_db_table_name',
28 );
29  
30 1 parameter document_client_attribute_name => (
31 isa => 'Str',
32 default => 'dynamodb_document_client',
33 );
34  
35 parameter document_client_builder => (
36 isa => 'CodeRef',
37 0 ▶ default => sub { sub { PawsX::DynamoDB::DocumentClient->new() } },
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 1 );
39  
40 parameter force_type => (
41 isa => 'HashRef',
42 0 ▶ default => sub {{}},
Subroutine __ANON__: not called CC=1 SCAR=6.9
43 1 );
44  
45 0 ▶role {
Subroutine __ANON__: not called CC=1 SCAR=6.9
46 0 my $p = shift;
47  
48 0 requires 'pack';
49 0 requires 'unpack';
50  
51 0 my $table_name_method = $p->table_name_method;
52 0 my $client_attr = $p->document_client_attribute_name;
53 0 my $client_builder = $p->document_client_builder;
54 0 my $force_type = $p->force_type;
55  
56 0 has $client_attr => (
57 is => 'ro',
58 isa => HasMethods[qw(get put)],
59 lazy => 1,
60 traits => [ 'DoNotSerialize' ],
61 default => $client_builder,
62 );
63  
64 0 ▶ method $table_name_method => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
65 0 ▶ my $class = ref $_[0] || $_[0];
Condition0%0/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table0%0/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
66 0 ▶ return $p->table_name if $p->table_name;
Branch: 1 branch
BranchTrueFalseTotal
if $p->table_name 0 0 0
67 0 die "$class: no table name defined!";
68 0 };
69  
70 0 ▶ method load => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
71 0 my ( $class, $item_key, %args ) = @_;
72 0 ▶ my $client = $args{dynamodb_document_client} || $client_builder->();
Condition0%0/3
$args{'dynamodb_document_client'} || &$client_builder()
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'dynamodb_document_client'} || &$client_builder()
$args{'dynamodb_document_client'} &$client_builder()
Truth table0%0/3
A || B
A= $args{'dynamodb_document_client'}B= &$client_builder()
ABresult
1X1
011
000
73 0 ▶ my $inject = $args{inject} || {};
Condition0%0/2
$args{'inject'} || {}
l!l
00
MC/DC0%0/1
$args{'inject'} || {}
$args{'inject'}
Truth table0%0/2
A
A= $args{'inject'}
Aresult
11
00
74 0 my $table_name = $class->$table_name_method();
75  
76 0 my $packed = $client->get(
77 TableName => $table_name,
78 Key => {
79 $p->key_attr => $item_key,
80 },
81 ConsistentRead => 1,
82 force_type => $force_type,
83 );
84  
85 0 ▶ return undef unless $packed;
Branch: 1 branch
BranchTrueFalseTotal
unless $packed 0 0 0
86  
87 # Deserialize JSON values
88 0 foreach my $key (keys %$packed) {
89 0 my $value = $packed->{$key};
90 0 ▶ if ($value && $value =~ /^\$json\$v(\d+)\$:(.+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $value =~ /^\$json\$v(\d+)\$:(.+)$/u) 0 0 0
Condition0%0/3
$value and $value =~ /^\$json\$v(\d+)\$:(.+)$/u
!ll&&!rl&&r
000
MC/DC0%0/2
$value and $value =~ /^\$json\$v(\d+)\$:(.+)$/u
$value $value =~ /^\$json\$v(\d+)\$:(.+)$/u
Truth table0%0/3
A and B
A= $valueB= $value =~ /^\$json\$v(\d+)\$:(.+)$/u
ABresult
0X0
100
111
91 0 my ($version, $json) = ($1, $2);
92 0 state $coder = JSON::MaybeXS->new(
93 utf8 => 1,
94 canonical => 1,
95 allow_nonref => 1,
96 );
97 0 $packed->{$key} = $coder->decode($json);
98 }
99 }
100  
101 0 return $class->unpack(
102 $packed,
103 inject => {
104 %$inject,
105 $client_attr => $client,
106 }
107 );
108 0 };
109  
110 0 ▶ method store => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
111 0 my ( $self ) = @_;
112 0 my $client = $self->$client_attr;
113 0 my $table_name = $self->$table_name_method();
114 0 my $packed = $self->pack;
115 0 $client->put(
116 TableName => $table_name,
117 Item => $packed,
118 force_type => $force_type,
119 );
120 0 };
121 1 };
122  
123 1 1;
124 __END__
↑ Summary