blib/lib/WebDyne/Cloudflare/Hyperdrive/Transport.pm

filter: Statementstmt 93.9% 62 / 66 Branchbran 62.5% 15 / 24 Conditioncond 48.2% 27 / 56 MC/DCmcdc 20.0% 5 / 25 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 2 totaltotal 65.2% 120 / 184 CC 32 SCAR 32.3
CC
32
Cov
71%
new
40.6
call
22.4
BEGIN
1.0
CRAP 25.2
↑ Summary blib/lib/WebDyne/Cloudflare/Hyperdrive/Codec.pm »
1 package WebDyne::Cloudflare::Hyperdrive::Transport;
2  
3 2 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Future::AsyncAwait;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use WebDyne::Cloudflare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use WebDyne::Cloudflare::Hyperdrive::Codec;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use WebDyne::Cloudflare::Hyperdrive::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION='0.001';
13 2 our $HOST_CALL;
14 2 my $json_or=JSON::PP->new()->canonical();
15  
16 9 ▶sub new {
Subroutine new: called CC=17 SCAR=37.0
Pod undocumented
17 9 my ($class, %opt)=@_;
18 9 my $scope_hr=$opt{'scope'};
19 9 ▶ die "Hyperdrive transport requires a PAGI scope\n" unless ref($scope_hr) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $scope_hr eq "HASH" 0 9 9
20 my $extension_hr=(ref($scope_hr->{'extensions'}) eq 'HASH')
21 9 ▶ ? $scope_hr->{'extensions'}{'webdyne.cloudflare.hyperdrive'} : undef;
Branch: 1 branch
BranchTrueFalseTotal
ref $scope_hr->{'extensions'} eq 'HASH' ? : 9 0 9
22 die "Missing or invalid Hyperdrive capability\n"
23 unless (ref($extension_hr) eq 'HASH')&&defined($extension_hr->{'version'})
24 &&!ref($extension_hr->{'version'})&&($extension_hr->{'version'} eq '1')
25 &&defined($extension_hr->{'capability'})&&!ref($extension_hr->{'capability'})
26 9 ▶ &&length($extension_hr->{'capability'})&&(ref($extension_hr->{'bindings'}) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
unless ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"} and ref $extension_hr->{"bindings"} eq "ARRAY" 0 9 9
Condition33%7/21
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"} and ref $extension_hr->{"bindings"} eq "ARRAY"
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"}
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"}
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"}
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"}
!ll&&!rl&&r
009
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"}
!ll&&!rl&&r
009
MC/DC0%0/8
ref $extension_hr eq "HASH" and defined $extension_hr->{"version"} and not ref $extension_hr->{"version"} and $extension_hr->{"version"} eq 1 and defined $extension_hr->{"capability"} and not ref $extension_hr->{"capability"} and length $extension_hr->{"capability"} and ref $extension_hr->{"bindings"} eq "ARRAY"
ref $extension_hr eq "HASH" defined $extension_hr->{"version"} not ref $extension_hr->{"version"} $extension_hr->{"version"} eq 1 defined $extension_hr->{"capability"} not ref $extension_hr->{"capability"} length $extension_hr->{"capability"} ref $extension_hr->{"bindings"} eq "ARRAY"
Truth table11%1/9
A and B and not(C) and D and E and not(F) and G and H
A= ref $extension_hr eq "HASH"B= defined $extension_hr->{"version"}C= not ref $extension_hr->{"version"}D= $extension_hr->{"version"} eq 1E= defined $extension_hr->{"capability"}F= not ref $extension_hr->{"capability"}G= length $extension_hr->{"capability"}H= ref $extension_hr->{"bindings"} eq "ARRAY"
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
27 9 ▶ my $binding=$opt{'binding'}//'DB';
Condition100%2/2
$opt{"binding"} // "DB"
l!l
18
MC/DC100%1/1
$opt{"binding"} // "DB"
$opt{"binding"}
Truth table100%2/2
A
A= $opt{"binding"}
Aresult
11
00
28 9 ▶ die "Invalid Hyperdrive binding\n" unless !ref($binding)&&($binding=~/\A[A-Z_][A-Z0-9_]*\z/);
Branch: 1 branch
BranchTrueFalseTotal
unless not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u 0 9 9
Condition33%1/3
not ref $binding and $binding =~ /\A[A-Z_][A-Z0-9_]*\z/u
!ll&&!rl&&r
009
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
29 die "Hyperdrive binding is unavailable\n"
30 9 ▶ unless grep { defined($_)&&!ref($_)&&($_ eq $binding) } @{$extension_hr->{'bindings'}};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {defined $_ and not ref $_ and $_ eq $binding;} @{$$extension_hr{"bindings"};} 1 8 9
Condition50%3/6
defined $_ && !ref($_) && $_ eq $binding
!ll&&!rl&&r
018
defined $_ and not ref $_
!ll&&!rl&&r
009
MC/DC33%1/3
defined $_ && !ref($_) && $_ eq $binding
defined $_ not ref $_ $_ eq $binding
Truth table50%2/4
A and not(B) && C
A= defined $_B= not ref $_C= $_ eq $binding
ABCresult
0XX0
10X0
1100
1111
31 8 return bless({ capability => $extension_hr->{'capability'}, binding => $binding }, $class);
32 }
33  
34  
35 8 ▶async sub call {
Subroutine call: called CC=16 SCAR=31.1
Pod undocumented
36 8 my ($self, $operation, %opt)=@_;
37 8 ▶ die "Invalid Hyperdrive operation\n" unless defined($operation)&&!ref($operation)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $operation and not ref $operation and $operation =~ /\A(?:open|query|begin|commit|rollback|disconnect)\z/u 0 8 8
Condition33%2/6
defined $operation and not ref $operation and $operation =~ /\A(?:open|query|begin|commit|rollback|disconnect)\z/u
!ll&&!rl&&r
008
defined $operation and not ref $operation
!ll&&!rl&&r
008
MC/DC0%0/3
defined $operation and not ref $operation and $operation =~ /\A(?:open|query|begin|commit|rollback|disconnect)\z/u
defined $operation not ref $operation $operation =~ /\A(?:open|query|begin|commit|rollback|disconnect)\z/u
Truth table25%1/4
A and not(B) and C
A= defined $operationB= not ref $operationC= $operation =~ /\A(?:open|query|begin|commit|rollback|disconnect)\z/u
ABCresult
0XX0
10X0
1100
1111
38 &&($operation=~/\A(?:open|query|begin|commit|rollback|disconnect)\z/);
39 die "Cannot override Hyperdrive capability\n"
40 8 ▶ if grep { exists($opt{$_}) } qw(version capability binding operation);
Branch: 1 branch
BranchTrueFalseTotal
if grep {exists $opt{$_};} "version", "capability", "binding", "operation" 1 7 8
41 my $wire_hr={ %opt, version => 1, capability => $self->{'capability'},
42 7 binding => $self->{'binding'}, operation => $operation };
43 7 $wire_hr=WebDyne::Cloudflare::json_value($wire_hr);
44 7 my $wire=$json_or->encode($wire_hr);
45 7 my $response;
46 7 ▶ if ($HOST_CALL) { $response=$HOST_CALL->($wire) }
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::Cloudflare::Hyperdrive::Transport::HOST_CALL) { } 7 0 7
47 else {
48 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 0 my $host_cr=*{'WebDyne::Cloudflare::Hyperdrive::Transport::host_call'}{'CODE'};
50 0 ▶ die "Hyperdrive host adapter is not registered\n" unless $host_cr;
Branch: 1 branch
BranchTrueFalseTotal
unless $host_cr 0 0 0
51 0 $response=$host_cr->($wire);
52 }
53 7 my $response_hr=eval { $json_or->decode($response) };
54 die "Invalid Hyperdrive host response\n" unless (ref($response_hr) eq 'HASH')
55 &&defined($response_hr->{'version'})&&!ref($response_hr->{'version'})
56 7 ▶ &&($response_hr->{'version'} eq '1')&&JSON::PP::is_bool($response_hr->{'ok'});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $response_hr eq "HASH" and defined $response_hr->{"version"} and not ref $response_hr->{"version"} and $response_hr->{"version"} eq 1 and JSON::PP::is_bool($response_hr->{"ok"}) 3 4 7
Condition83%10/12
ref $response_hr eq "HASH" and defined $response_hr->{"version"} and not ref $response_hr->{"version"} and $response_hr->{"version"} eq 1 and JSON::PP::is_bool($response_hr->{"ok"})
!ll&&!rl&&r
214
ref $response_hr eq "HASH" and defined $response_hr->{"version"} and not ref $response_hr->{"version"} and $response_hr->{"version"} eq 1
!ll&&!rl&&r
115
ref $response_hr eq "HASH" and defined $response_hr->{"version"} and not ref $response_hr->{"version"}
!ll&&!rl&&r
106
ref $response_hr eq "HASH" and defined $response_hr->{"version"}
!ll&&!rl&&r
016
MC/DC60%3/5
ref $response_hr eq "HASH" and defined $response_hr->{"version"} and not ref $response_hr->{"version"} and $response_hr->{"version"} eq 1 and JSON::PP::is_bool($response_hr->{"ok"})
ref $response_hr eq "HASH" defined $response_hr->{"version"} not ref $response_hr->{"version"} $response_hr->{"version"} eq 1 JSON::PP::is_bool($response_hr->{"ok"})
Truth table66%4/6
A and B and not(C) and D and E
A= ref $response_hr eq "HASH"B= defined $response_hr->{"version"}C= not ref $response_hr->{"version"}D= $response_hr->{"version"} eq 1E= JSON::PP::is_bool($response_hr->{"ok"})
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
57 4 ▶ if (!$response_hr->{'ok'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response_hr->{"ok"}) 2 2 4
58 2 my $error_hr=$response_hr->{'error'};
59 die "Invalid Hyperdrive host error\n" unless ref($error_hr) eq 'HASH'
60 2 ▶ &&defined($error_hr->{'message'})&&!ref($error_hr->{'message'});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $error_hr eq "HASH" and defined $error_hr->{"message"} and not ref $error_hr->{"message"} 0 2 2
Condition33%2/6
ref $error_hr eq "HASH" and defined $error_hr->{"message"} and not ref $error_hr->{"message"}
!ll&&!rl&&r
002
ref $error_hr eq "HASH" and defined $error_hr->{"message"}
!ll&&!rl&&r
002
MC/DC0%0/3
ref $error_hr eq "HASH" and defined $error_hr->{"message"} and not ref $error_hr->{"message"}
ref $error_hr eq "HASH" defined $error_hr->{"message"} not ref $error_hr->{"message"}
Truth table25%1/4
A and B and not(C)
A= ref $error_hr eq "HASH"B= defined $error_hr->{"message"}C= not ref $error_hr->{"message"}
ABCresult
0XX0
10X0
1100
1111
61 2 die WebDyne::Cloudflare::Hyperdrive::Error->new(%{$error_hr});
62 }
63 2 return WebDyne::Cloudflare::Hyperdrive::Codec::result($response_hr->{'result'});
64 2 }
65  
66 2 1;
↑ Summary blib/lib/WebDyne/Cloudflare/Hyperdrive/Codec.pm »