blib/lib/WebDyne/Cloudflare/D1.pm

filter: Statementstmt 97.8% 180 / 184 Branchbran 87.5% 77 / 88 Conditioncond 69.0% 78 / 113 MC/DCmcdc 48.2% 28 / 58 Subroutinesub 100% 30 / 30 Podpod 0.0% 0 / 15 totaltotal 80.5% 393 / 488 CC 85 SCAR 25.0
CC
85
Cov
87%
new
29.1
decode_result
19.0
execute
9.0
CRAP 12.2
« blib/lib/WebDyne/Cloudflare/SecretsStore.pm ↑ Summary blib/lib/WebDyne/Cloudflare/KV.pm »
1 package WebDyne::Cloudflare::D1;
2  
3 5 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use WebDyne::Cloudflare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Encode qw(decode FB_CROAK);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use MIME::Base64 qw(decode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use WebDyne::Cloudflare::D1::Blob;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use WebDyne::Cloudflare::D1::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use WebDyne::Cloudflare::D1::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 our $VERSION='0.001';
18 5 our $HOST_CALL;
19  
20 5 ▶use constant EXTENSION_NAME => 'webdyne.cloudflare.d1';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use constant PROTOCOL_VERSION => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 5 my $json_or=JSON::PP->new()->canonical()->allow_nonref();
24  
25 15 ▶sub new {
Subroutine new: called CC=20 SCAR=33.7
Pod undocumented
26 15 my ($class, %opt)=@_;
27 15 my $scope_hr=$opt{'scope'};
28 15 ▶ die "WebDyne::Cloudflare::D1 requires a PAGI scope hash\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $scope_hr eq "HASH" 0 15 15
29 unless ref($scope_hr) eq 'HASH';
30 my $extension_hr=(ref($scope_hr->{'extensions'}) eq 'HASH')
31 15 ▶ ? $scope_hr->{'extensions'}{EXTENSION_NAME()}
Branch: 1 branch
BranchTrueFalseTotal
ref $scope_hr->{'extensions'} eq 'HASH' ? : 13 2 15
32 : undef;
33 15 ▶ die "PAGI scope has no " . EXTENSION_NAME() . " capability\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension_hr eq "HASH" 3 12 15
34 unless ref($extension_hr) eq 'HASH';
35 die "Unsupported D1 capability protocol\n"
36 unless (defined($extension_hr->{'version'})
37 &&!ref($extension_hr->{'version'})
38 12 ▶ &&($extension_hr->{'version'} eq PROTOCOL_VERSION()));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 1 11 12
Condition50%3/6
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
!ll&&!rl&&r
0111
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"}
!ll&&!rl&&r
0012
MC/DC33%1/3
defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
defined $extension_hr->{"version"} not ref $extension_hr->{"version"} $extension_hr->{"version"} eq 1
Truth table50%2/4
A and not(B) and C
A= defined $extension_hr->{"version"}B= not ref $extension_hr->{"version"}C= $extension_hr->{"version"} eq 1
ABCresult
0XX0
10X0
1100
1111
39 die "Invalid D1 capability token\n"
40 unless (defined($extension_hr->{'capability'})
41 &&!ref($extension_hr->{'capability'})
42 11 ▶ &&length($extension_hr->{'capability'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"} 0 11 11
Condition33%2/6
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
!ll&&!rl&&r
0011
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"}
!ll&&!rl&&r
0011
MC/DC0%0/3
defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
defined $extension_hr->{"capability"} not ref $extension_hr->{"capability"} length $extension_hr->{"capability"}
Truth table25%1/4
A and not(B) and C
A= defined $extension_hr->{"capability"}B= not ref $extension_hr->{"capability"}C= length $extension_hr->{"capability"}
ABCresult
0XX0
10X0
1100
1111
43  
44 11 ▶ my $binding=(defined($opt{'binding'}) ? $opt{'binding'} : 'DB');
Branch: 1 branch
BranchTrueFalseTotal
defined $opt{'binding'} ? : 4 7 11
45 11 ▶ die "Invalid D1 binding name '$binding'\n"
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u 0 11 11
Condition33%1/3
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
!ll&&!rl&&r
0011
MC/DC0%0/2
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
not ref $binding $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
Truth table33%1/3
not(A) and B
A= not ref $bindingB= $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
ABresult
0X0
100
111
46 unless (!ref($binding)&&($binding=~/\A[A-Z_][A-Z0-9_]*\z/));
47 11 my $bindings_ar=$extension_hr->{'bindings'};
48 11 ▶ die "Invalid D1 capability binding list\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $bindings_ar eq "ARRAY" 1 10 11
49 unless (ref($bindings_ar) eq 'ARRAY');
50 10 ▶ my %binding=map { $_ => 1 } grep { defined($_)&&!ref($_) } @{$bindings_ar};
Condition33%1/3
defined $_ && !ref($_)
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
51 die "D1 binding '$binding' is not available to this request\n"
52 10 ▶ unless $binding{$binding};
Branch: 1 branch
BranchTrueFalseTotal
unless $binding{$binding} 0 10 10
53  
54 my $self=bless({
55 binding => $binding,
56 capability => $extension_hr->{'capability'},
57 sessions => (ref($extension_hr->{'session_bindings'}) eq 'ARRAY'
58 10 ▶ &&grep { defined($_)&&!ref($_)&&($_ eq $binding) } @{$extension_hr->{'session_bindings'}}) ? 1 : 0,
Branch: 1 branch
BranchTrueFalseTotal
ref $extension_hr->{'session_bindings'} eq 'ARRAY' && grep({defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{'session_bindings'};}) ? : 1 9 10
Condition55%5/9
ref $extension_hr->{"session_bindings"} eq "ARRAY" and grep {defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{"session_bindings"};}
!ll&&!rl&&r
811
defined $_ && !ref($_) && $_ eq $binding
!ll&&!rl&&r
001
defined $_ and not ref $_
!ll&&!rl&&r
001
MC/DC100%2/2
ref $extension_hr->{"session_bindings"} eq "ARRAY" and grep {defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{"session_bindings"};}
ref $extension_hr->{"session_bindings"} eq "ARRAY" grep {defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{"session_bindings"};}
MC/DC0%0/3
defined $_ && !ref($_) && $_ eq $binding
defined $_ not ref $_ $_ eq $binding
Truth table100%3/3
A and B
A= ref $extension_hr->{"session_bindings"} eq "ARRAY"B= grep {defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{"session_bindings"};}
ABresult
0X0
100
111
Truth table25%1/4
A and not(B) && C
A= defined $_B= not ref $_C= $_ eq $binding
ABCresult
0XX0
10X0
1100
1111
59 }, $class);
60 10 return $self;
61 }
62  
63  
64 17 ▶async sub with_session {
Subroutine with_session: called CC=9 SCAR=22.0
Pod undocumented
65 17 my ($self, $constraint)=@_;
66 17 ▶ die "D1 Sessions API is unavailable for this binding\n" unless $self->{'sessions'};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"sessions"} 1 16 17
67 16 ▶ die "Cannot create a session from a session\n" if exists($self->{'session'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"session"} 3 13 16
68 13 ▶ die "D1 session requires a non-empty constraint or bookmark\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @_ <= 2 and @_ == 1 || defined $constraint && !ref($constraint) && length $constraint 4 9 13
Condition91%11/12
@_ <= 2 and @_ == 1 || defined $constraint && !ref($constraint) && length $constraint
!ll&&!rl&&r
049
@_ == 1 or defined $constraint and not ref $constraint and length $constraint
l!l&&r!l&&!r
634
defined $constraint and not ref $constraint and length $constraint
!ll&&!rl&&r
313
defined $constraint and not ref $constraint
!ll&&!rl&&r
124
MC/DC80%4/5
@_ <= 2 and @_ == 1 || defined $constraint && !ref($constraint) && length $constraint
@_ <= 2 @_ == 1 defined $constraint not ref $constraint length $constraint
Truth table83%5/6
A and B or C and not(D) and E
A= @_ <= 2B= @_ == 1C= defined $constraintD= not ref $constraintE= length $constraint
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
69 unless ((@_<=2)&&((@_==1)||(defined($constraint)&&!ref($constraint)&&length($constraint))));
70 9 ▶ my $id=await $self->execute(operation => 'with_session',
Branch: 1 branch
BranchTrueFalseTotal
defined $constraint ? : 3 6 9
71 constraint => (defined($constraint) ? $constraint : 'first-unconstrained'));
72 5 require WebDyne::Cloudflare::D1::Session;
73 5 return bless({%{$self}, session => $id}, 'WebDyne::Cloudflare::D1::Session');
74 5 }
75  
76  
77 4 ▶sub binding {
Subroutine binding: called CC=1 SCAR=0.0
Pod undocumented
78 4 return shift()->{'binding'};
79 }
80  
81  
82 24 ▶sub blob {
Subroutine blob: called CC=7 SCAR=19.5
Pod undocumented
83 # Accept function, class and object calls without discarding payload bytes.
84 #
85 24 ▶ shift() if ((@_>1)&&(defined($_[0])
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 and (defined $_[0] and builtin::blessed($_[0]) || !ref($_[0]) && $_[0] eq __PACKAGE__) 16 8 24
Condition83%10/12
@_ > 1 and (defined $_[0] and builtin::blessed($_[0]) || !ref($_[0]) && $_[0] eq __PACKAGE__)
!ll&&!rl&&r
7116
defined $_[0] and builtin::blessed($_[0]) || !ref($_[0]) && $_[0] eq __PACKAGE__
!ll&&!rl&&r
0116
builtin::blessed($_[0]) or not ref $_[0] and $_[0] eq __PACKAGE__
l!l&&r!l&&!r
5111
not ref $_[0] and $_[0] eq __PACKAGE__
!ll&&!rl&&r
0111
MC/DC60%3/5
@_ > 1 and (defined $_[0] and builtin::blessed($_[0]) || !ref($_[0]) && $_[0] eq __PACKAGE__)
@_ > 1 defined $_[0] builtin::blessed($_[0]) not ref $_[0] $_[0] eq __PACKAGE__
Truth table66%4/6
A and B and C or not(D) and E
A= @_ > 1B= defined $_[0]C= builtin::blessed($_[0])D= not ref $_[0]E= $_[0] eq __PACKAGE__
ABCDEresult
0XXXX0
10XXX0
1100X0
110100
111XX1
110111
86 &&(blessed($_[0])||(!ref($_[0])&&($_[0] eq __PACKAGE__)))));
87 24 ▶ die "D1 blob requires exactly one byte string\n" unless (@_==1);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 1 1 23 24
88 23 return WebDyne::Cloudflare::D1::Blob->new($_[0]);
89 }
90  
91  
92 38 ▶sub prepare {
Subroutine prepare: called CC=4 SCAR=17.1
Pod undocumented
93 38 my ($self, $sql)=@_;
94 38 ▶ die "D1 prepare requires a non-empty SQL string\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sql and not ref $sql and length $sql 0 38 38
Condition33%2/6
defined $sql and not ref $sql and length $sql
!ll&&!rl&&r
0038
defined $sql and not ref $sql
!ll&&!rl&&r
0038
MC/DC0%0/3
defined $sql and not ref $sql and length $sql
defined $sql not ref $sql length $sql
Truth table25%1/4
A and not(B) and C
A= defined $sqlB= not ref $sqlC= length $sql
ABCresult
0XX0
10X0
1100
1111
95 unless (defined($sql)&&!ref($sql)&&length($sql));
96 38 return WebDyne::Cloudflare::D1::Statement->new(
97 database => $self,
98 sql => $sql,
99 );
100 }
101  
102  
103 4 ▶async sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
104 4 my ($self, $sql, @param)=@_;
105 4 return await $self->prepare($sql)->bind(@param)->run();
106 5 }
107  
108  
109 4 ▶async sub all {
Subroutine all: called CC=1 SCAR=0.0
Pod undocumented
110 4 my ($self, $sql, @param)=@_;
111 4 return await $self->prepare($sql)->bind(@param)->all();
112 5 }
113  
114  
115 7 ▶async sub first {
Subroutine first: called CC=1 SCAR=0.0
Pod undocumented
116 7 my ($self, $sql, @param)=@_;
117 7 return await $self->prepare($sql)->bind(@param)->first();
118 5 }
119  
120  
121 30 ▶async sub batch {
Subroutine batch: called CC=7 SCAR=19.5
Pod undocumented
122 30 my ($self, $statements_ar)=@_;
123 die "D1 batch requires one non-empty array of prepared statements\n"
124 30 ▶ unless ((@_==2)&&(ref($statements_ar) eq 'ARRAY')&&@{$statements_ar});
Branch: 1 branch
BranchTrueFalseTotal
unless @_ == 2 and ref $statements_ar eq "ARRAY" and @{$statements_ar;} 4 26 30
Condition83%5/6
@_ == 2 and ref $statements_ar eq "ARRAY" and @{$statements_ar;}
!ll&&!rl&&r
3126
@_ == 2 and ref $statements_ar eq "ARRAY"
!ll&&!rl&&r
0327
MC/DC66%2/3
@_ == 2 and ref $statements_ar eq "ARRAY" and @{$statements_ar;}
@_ == 2 ref $statements_ar eq "ARRAY" @{$statements_ar;}
Truth table75%3/4
A and B and C
A= @_ == 2B= ref $statements_ar eq "ARRAY"C= @{$statements_ar;}
ABCresult
0XX0
10X0
1100
1111
125  
126 # Validate every statement before crossing the host boundary.
127 #
128 26 my @request;
129 26 foreach my $statement_or (@{$statements_ar}) {
130 36 ▶ die "D1 batch entries must be D1 prepared statements\n"
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($statement_or) and $statement_or->isa("WebDyne::Cloudflare::D1::Statement") 4 32 36
Condition100%3/3
builtin::blessed($statement_or) and $statement_or->isa("WebDyne::Cloudflare::D1::Statement")
!ll&&!rl&&r
3132
MC/DC100%2/2
builtin::blessed($statement_or) and $statement_or->isa("WebDyne::Cloudflare::D1::Statement")
builtin::blessed($statement_or) $statement_or->isa("WebDyne::Cloudflare::D1::Statement")
Truth table100%3/3
A and B
A= builtin::blessed($statement_or)B= $statement_or->isa("WebDyne::Cloudflare::D1::Statement")
ABresult
0X0
100
111
131 unless (blessed($statement_or)
132 &&$statement_or->isa('WebDyne::Cloudflare::D1::Statement'));
133 32 push(@request, $statement_or->batch_request($self));
134 }
135 12 return await $self->execute(operation => 'batch', statements => \@request);
136 5 }
137  
138  
139 65 ▶sub encode_parameter {
Subroutine encode_parameter: called CC=9 SCAR=22.0
Pod undocumented
140 65 my ($value_ref)=@_;
141 65 ▶ return undef unless defined($value_ref);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value_ref 9 56 65
142 56 ▶ if (blessed($value_ref)&&$value_ref->isa('WebDyne::Cloudflare::D1::Blob')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($value_ref) and $value_ref->isa("WebDyne::Cloudflare::D1::Blob")) 10 46 56
Condition100%3/3
builtin::blessed($value_ref) and $value_ref->isa("WebDyne::Cloudflare::D1::Blob")
!ll&&!rl&&r
37910
MC/DC100%2/2
builtin::blessed($value_ref) and $value_ref->isa("WebDyne::Cloudflare::D1::Blob")
builtin::blessed($value_ref) $value_ref->isa("WebDyne::Cloudflare::D1::Blob")
Truth table100%3/3
A and B
A= builtin::blessed($value_ref)B= $value_ref->isa("WebDyne::Cloudflare::D1::Blob")
ABresult
0X0
100
111
143 10 return $value_ref->wire_value();
144 }
145 46 ▶ if (!ref($value_ref)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value_ref) 35 11 46
146 # Decode web text strictly, preserving ASCII numeric/string flags.
147 # Binary input must use blob().
148 #
149 35 ▶ return decode('UTF-8', $value_ref, FB_CROAK)
Branch: 1 branch
BranchTrueFalseTotal
if not utf8::is_utf8($value_ref) and $value_ref =~ /[\x80-\xff]/u 11 24 35
Condition66%2/3
not utf8::is_utf8($value_ref) and $value_ref =~ /[\x80-\xff]/u
!ll&&!rl&&r
02411
MC/DC50%1/2
not utf8::is_utf8($value_ref) and $value_ref =~ /[\x80-\xff]/u
not utf8::is_utf8($value_ref) $value_ref =~ /[\x80-\xff]/u
Truth table66%2/3
not(A) and B
A= not utf8::is_utf8($value_ref)B= $value_ref =~ /[\x80-\xff]/u
ABresult
0X0
100
111
150 if (!utf8::is_utf8($value_ref)&&($value_ref=~/[\x80-\xff]/));
151 24 return $value_ref;
152 }
153 11 ▶ return $value_ref if (blessed($value_ref)&&$value_ref->isa('JSON::PP::Boolean'));
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($value_ref) and $value_ref->isa("JSON::PP::Boolean") 9 2 11
Condition66%2/3
builtin::blessed($value_ref) and $value_ref->isa("JSON::PP::Boolean")
!ll&&!rl&&r
209
MC/DC50%1/2
builtin::blessed($value_ref) and $value_ref->isa("JSON::PP::Boolean")
builtin::blessed($value_ref) $value_ref->isa("JSON::PP::Boolean")
Truth table66%2/3
A and B
A= builtin::blessed($value_ref)B= $value_ref->isa("JSON::PP::Boolean")
ABresult
0X0
100
111
154 2 die "D1 bind values must be scalars, undef, JSON booleans, or D1 blobs\n";
155 }
156  
157  
158 41 ▶sub decode_value {
Subroutine decode_value: called CC=6 SCAR=21.4
Pod undocumented
159 41 my ($value_ref)=@_;
160 41 ▶ return $value_ref unless (ref($value_ref) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value_ref eq "HASH" 34 7 41
161 die "D1 host returned an invalid blob value\n"
162 unless (defined($value_ref->{'type'})&&($value_ref->{'type'} eq 'blob')
163 7 ▶ &&defined($value_ref->{'base64'})&&!ref($value_ref->{'base64'}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value_ref->{"type"} and $value_ref->{"type"} eq "blob" and defined $value_ref->{"base64"} and not ref $value_ref->{"base64"} 0 7 7
Condition33%3/9
defined $value_ref->{"type"} and $value_ref->{"type"} eq "blob" and defined $value_ref->{"base64"} and not ref $value_ref->{"base64"}
!ll&&!rl&&r
007
defined $value_ref->{"type"} and $value_ref->{"type"} eq "blob" and defined $value_ref->{"base64"}
!ll&&!rl&&r
007
defined $value_ref->{"type"} and $value_ref->{"type"} eq "blob"
!ll&&!rl&&r
007
MC/DC0%0/4
defined $value_ref->{"type"} and $value_ref->{"type"} eq "blob" and defined $value_ref->{"base64"} and not ref $value_ref->{"base64"}
defined $value_ref->{"type"} $value_ref->{"type"} eq "blob" defined $value_ref->{"base64"} not ref $value_ref->{"base64"}
Truth table20%1/5
A and B and C and not(D)
A= defined $value_ref->{"type"}B= $value_ref->{"type"} eq "blob"C= defined $value_ref->{"base64"}D= not ref $value_ref->{"base64"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
164 7 return decode_base64($value_ref->{'base64'});
165 }
166  
167  
168 11 ▶sub decode_row {
Subroutine decode_row: called CC=2 SCAR=7.0
Pod undocumented
169 11 my ($row_hr)=@_;
170 11 ▶ die "D1 host returned an invalid row\n" unless (ref($row_hr) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $row_hr eq "HASH" 0 11 11
171 11 return {map { $_ => decode_value($row_hr->{$_}) } keys(%{$row_hr})};
172 }
173  
174  
175 52 ▶sub decode_result {
Subroutine decode_result: called CC=19 SCAR=29.4
Pod undocumented
176 52 my ($request_hr, $result_ref)=@_;
177  
178 52 ▶ if ($request_hr->{'operation'} eq 'with_session' || $request_hr->{'operation'} eq 'get_bookmark') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_hr->{"operation"} eq "with_session" or $request_hr->{"operation"} eq "get_bookmark") 13 39 52
Condition100%3/3
$request_hr->{"operation"} eq "with_session" or $request_hr->{"operation"} eq "get_bookmark"
l!l&&r!l&&!r
9439
MC/DC100%2/2
$request_hr->{"operation"} eq "with_session" or $request_hr->{"operation"} eq "get_bookmark"
$request_hr->{"operation"} eq "with_session" $request_hr->{"operation"} eq "get_bookmark"
Truth table100%3/3
A or B
A= $request_hr->{"operation"} eq "with_session"B= $request_hr->{"operation"} eq "get_bookmark"
ABresult
1X1
011
000
179 die WebDyne::Cloudflare::D1::Error->new(
180 name => 'D1_PROTOCOL_ERROR', message => 'host returned an invalid session value',
181 13 ▶ ) unless ((!defined($result_ref)&&($request_hr->{'operation'} eq 'get_bookmark'))
Branch: 1 branch
BranchTrueFalseTotal
unless not defined $result_ref and $request_hr->{"operation"} eq "get_bookmark" or defined $result_ref and not ref $result_ref and length $result_ref 4 9 13
Condition100%12/12
not defined $result_ref and $request_hr->{"operation"} eq "get_bookmark" or defined $result_ref and not ref $result_ref and length $result_ref
l!l&&r!l&&!r
364
not defined $result_ref and $request_hr->{"operation"} eq "get_bookmark"
!ll&&!rl&&r
913
defined $result_ref and not ref $result_ref and length $result_ref
!ll&&!rl&&r
316
defined $result_ref and not ref $result_ref
!ll&&!rl&&r
127
MC/DC80%4/5
not defined $result_ref and $request_hr->{"operation"} eq "get_bookmark" or defined $result_ref and not ref $result_ref and length $result_ref
not defined $result_ref $request_hr->{"operation"} eq "get_bookmark" defined $result_ref not ref $result_ref length $result_ref
Truth table55%5/9
not(A) and B or C and not(D) and E
A= not defined $result_refB= $request_hr->{"operation"} eq "get_bookmark"C= defined $result_refD= not ref $result_refE= length $result_ref
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
182 ||(defined($result_ref)&&!ref($result_ref)&&length($result_ref)));
183 9 return $result_ref;
184 }
185  
186 39 ▶ if ($request_hr->{'operation'} eq 'batch') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_hr->{"operation"} eq "batch") 10 29 39
187 die WebDyne::Cloudflare::D1::Error->new(
188 name => 'D1_PROTOCOL_ERROR',
189 message => 'host returned an invalid batch result count',
190 ) unless ((ref($result_ref) eq 'ARRAY')
191 10 ▶ &&(@{$result_ref}==@{$request_hr->{'statements'}}));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result_ref eq "ARRAY" and @{$result_ref;} == @{$request_hr->{"statements"};} 3 7 10
Condition100%3/3
ref $result_ref eq "ARRAY" and @{$result_ref;} == @{$request_hr->{"statements"};}
!ll&&!rl&&r
217
MC/DC100%2/2
ref $result_ref eq "ARRAY" and @{$result_ref;} == @{$request_hr->{"statements"};}
ref $result_ref eq "ARRAY" @{$result_ref;} == @{$request_hr->{"statements"};}
Truth table100%3/3
A and B
A= ref $result_ref eq "ARRAY"B= @{$result_ref;} == @{$request_hr->{"statements"};}
ABresult
0X0
100
111
192 7 foreach my $result_hr (@{$result_ref}) {
193 die WebDyne::Cloudflare::D1::Error->new(
194 name => 'D1_PROTOCOL_ERROR',
195 message => 'host returned an invalid batch result',
196 ) unless ((ref($result_hr) eq 'HASH')
197 9 ▶ &&(ref($result_hr->{'results'}) eq 'ARRAY')&&$result_hr->{'success'});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result_hr eq "HASH" and ref $result_hr->{"results"} eq "ARRAY" and $result_hr->{"success"} 2 7 9
Condition66%4/6
ref $result_hr eq "HASH" and ref $result_hr->{"results"} eq "ARRAY" and $result_hr->{"success"}
!ll&&!rl&&r
207
ref $result_hr eq "HASH" and ref $result_hr->{"results"} eq "ARRAY"
!ll&&!rl&&r
027
MC/DC33%1/3
ref $result_hr eq "HASH" and ref $result_hr->{"results"} eq "ARRAY" and $result_hr->{"success"}
ref $result_hr eq "HASH" ref $result_hr->{"results"} eq "ARRAY" $result_hr->{"success"}
Truth table50%2/4
A and B and C
A= ref $result_hr eq "HASH"B= ref $result_hr->{"results"} eq "ARRAY"C= $result_hr->{"success"}
ABCresult
0XX0
10X0
1100
1111
198 }
199 5 return [map { decode_result({operation => 'run'}, $_) } @{$result_ref}];
200 }
201  
202 # Decode only column values; rows can legitimately have type/base64 columns.
203 #
204 29 ▶ if ($request_hr->{'operation'} eq 'first') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_hr->{"operation"} eq "first") 7 22 29
205 7 ▶ return undef unless defined($result_ref);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result_ref 1 6 7
206 6 ▶ return exists($request_hr->{'column'})
Branch: 1 branch
BranchTrueFalseTotal
exists $request_hr->{'column'} ? : 1 5 6
207 ? decode_value($result_ref) : decode_row($result_ref);
208 }
209 22 ▶ if ($request_hr->{'operation'} eq 'raw') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request_hr->{"operation"} eq "raw") 4 18 22
210 4 return [map { [map { decode_value($_) } @{$_}] } @{$result_ref}];
211 }
212 18 $result_ref->{'results'}=[map { decode_row($_) } @{$result_ref->{'results'}}];
213 18 return $result_ref;
214 }
215  
216  
217 48 ▶sub call_host {
Subroutine call_host: called CC=3 SCAR=14.8
Pod undocumented
218 48 my ($wire)=@_;
219 48 ▶ return $HOST_CALL->($wire) if $HOST_CALL;
Branch: 1 branch
BranchTrueFalseTotal
if $WebDyne::Cloudflare::D1::HOST_CALL 48 0 48
220 5 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
221 0 my $host_call_cr=*{'WebDyne::Cloudflare::D1::Host::call'}{'CODE'};
222 0 ▶ die "D1 host adapter is not registered in this runtime\n" unless $host_call_cr;
Branch: 1 branch
BranchTrueFalseTotal
unless $host_call_cr 0 0 0
223 0 return $host_call_cr->($wire);
224 }
225  
226  
227 51 ▶async sub execute {
Subroutine execute: called CC=9 SCAR=22.0
Pod undocumented
228 51 my ($self, %request)=@_;
229 my $wire_hr={
230 version => PROTOCOL_VERSION,
231 capability => $self->{'capability'},
232 51 binding => $self->{'binding'},
233 %request,
234 };
235 51 ▶ $wire_hr->{'session'}=$self->{'session'} if exists($self->{'session'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"session"} 19 32 51
236 51 ▶ if ($request{'operation'} eq 'batch') {
Branch: 1 branch
BranchTrueFalseTotal
if ($request{'operation'} eq 'batch') { } 12 39 51
237 $wire_hr->{'statements'}=[map {
238 15 {sql => $_->{'sql'}, params => [map { encode_parameter($_) } @{$_->{'params'}}]}
239 12 } @{$request{'statements'}}];
240 }
241 else {
242 39 ▶ $wire_hr->{'params'}=[map { encode_parameter($_) } @{(defined($wire_hr->{'params'}) ? $wire_hr->{'params'} : [])}];
Branch: 1 branch
BranchTrueFalseTotal
defined $wire_hr->{'params'} ? : 26 13 39
243 }
244  
245 49 my $response_wire=call_host($json_or->encode(WebDyne::Cloudflare::json_value($wire_hr)));
246 48 my $response_hr=eval { $json_or->decode($response_wire) };
247 48 ▶ if ((ref($response_hr) ne 'HASH')||!exists($response_hr->{'ok'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $response_hr ne "HASH" or not exists $response_hr->{"ok"}) 1 47 48
Condition66%2/3
ref $response_hr ne "HASH" or not exists $response_hr->{"ok"}
l!l&&r!l&&!r
0147
MC/DC50%1/2
ref $response_hr ne "HASH" or not exists $response_hr->{"ok"}
ref $response_hr ne "HASH" not exists $response_hr->{"ok"}
Truth table66%2/3
A or not(B)
A= ref $response_hr ne "HASH"B= not exists $response_hr->{"ok"}
ABresult
1X1
011
000
248 1 ▶ my $detail=$@||'host returned an invalid response';
Condition50%1/2
$@ || 'host returned an invalid response'
l!l
01
MC/DC0%0/1
$@ || 'host returned an invalid response'
$@
Truth table50%1/2
A
A= $@
Aresult
11
00
249 1 die WebDyne::Cloudflare::D1::Error->new(
250 name => 'D1_PROTOCOL_ERROR',
251 message => $detail,
252 );
253 }
254 47 ▶ unless ($response_hr->{'ok'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_hr->{"ok"}) 2 45 47
255 2 ▶ my $error_hr=ref($response_hr->{'error'}) eq 'HASH' ? $response_hr->{'error'} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $response_hr->{'error'} eq 'HASH' ? : 2 0 2
256 2 die WebDyne::Cloudflare::D1::Error->new(%{$error_hr});
257 }
258 45 return decode_result(\%request, $response_hr->{'result'});
259 5 }
260  
261 5 1;
« blib/lib/WebDyne/Cloudflare/SecretsStore.pm ↑ Summary blib/lib/WebDyne/Cloudflare/KV.pm »