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

filter: Statementstmt 100% 70 / 70 Branchbran 77.5% 31 / 40 Conditioncond 65.0% 39 / 60 MC/DCmcdc 32.2% 10 / 31 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 3 totaltotal 74.7% 160 / 214 CC 43 SCAR 29.3
CC
43
Cov
82%
result
26.8
cell
21.0
parameters
7.0
CRAP 18.7
« blib/lib/WebDyne/Cloudflare/Hyperdrive/Transport.pm ↑ Summary lib/WebDyne/Cloudflare/DurableObject.pm »
1 package WebDyne::Cloudflare::Hyperdrive::Codec;
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 JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Scalar::Util qw(blessed);
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::Blob;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 our $VERSION='0.001';
12  
13 14 ▶sub parameters {
Subroutine parameters: called CC=7 SCAR=19.5
Pod undocumented
14 14 my (@param)=@_;
15 return [map {
16 14 my $value=$_;
17 19 ▶ if (!defined($value)) { ['null'] }
Branch: 4 branches
BranchTrueFalseTotal
if (not defined $value) { } 2 17 19
elsif (JSON::PP::is_bool($value)) { } 3 14 17
elsif (builtin::blessed($value) and $value->isa('WebDyne::Cloudflare::Hyperdrive::Blob')) { } 3 11 14
elsif (not ref $value) { } 9 2 11
18 3 elsif (JSON::PP::is_bool($value)) { ['bool', $value] }
19 ▶ elsif (blessed($value)&&$value->isa('WebDyne::Cloudflare::Hyperdrive::Blob')) {
Condition66%2/3
builtin::blessed($value) and $value->isa("WebDyne::Cloudflare::Hyperdrive::Blob")
!ll&&!rl&&r
1103
MC/DC50%1/2
builtin::blessed($value) and $value->isa("WebDyne::Cloudflare::Hyperdrive::Blob")
builtin::blessed($value) $value->isa("WebDyne::Cloudflare::Hyperdrive::Blob")
Truth table66%2/3
A and B
A= builtin::blessed($value)B= $value->isa("WebDyne::Cloudflare::Hyperdrive::Blob")
ABresult
0X0
100
111
20 3 ['bytes', unpack('H*', $value->bytes())];
21 }
22 elsif (!ref($value)) {
23 9 my $text="$value";
24 9 $text=WebDyne::Cloudflare::json_value($text);
25 8 ▶ die "Hyperdrive text cannot contain NUL\n" if index($text, "\0")>=0;
Branch: 1 branch
BranchTrueFalseTotal
if index($text, "\0") != -1 1 7 8
26 7 ['text', $text];
27 }
28 2 else { die "Hyperdrive parameters must be scalars, booleans or blobs\n" }
29 } @param];
30 }
31  
32  
33 14 ▶sub cell {
Subroutine cell: called CC=18 SCAR=30.5
Pod undocumented
34 14 my ($cell_ar)=@_;
35 14 ▶ die "Invalid Hyperdrive cell\n" unless ref($cell_ar) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cell_ar eq "ARRAY" 0 14 14
36 14 my ($type, $value)=@{$cell_ar};
37 14 ▶ die "Invalid Hyperdrive cell type\n" unless defined($type)&&!ref($type);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $type and not ref $type 0 14 14
Condition33%1/3
defined $type and not ref $type
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $type and not ref $type
defined $type not ref $type
Truth table33%1/3
A and not(B)
A= defined $typeB= not ref $type
ABresult
0X0
100
111
38 14 ▶ return undef if ($type eq 'null')&&(@{$cell_ar}==1);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "null" and @{$cell_ar;} == 1 1 13 14
Condition100%3/3
$type eq "null" and @{$cell_ar;} == 1
!ll&&!rl&&r
1211
MC/DC100%2/2
$type eq "null" and @{$cell_ar;} == 1
$type eq "null" @{$cell_ar;} == 1
Truth table100%3/3
A and B
A= $type eq "null"B= @{$cell_ar;} == 1
ABresult
0X0
100
111
39 13 ▶ die "Invalid Hyperdrive cell length\n" unless @{$cell_ar}==2;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$cell_ar;} == 2 0 13 13
40 13 ▶ return $value if ($type eq 'bool')&&JSON::PP::is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bool" and JSON::PP::is_bool($value) 1 12 13
Condition100%3/3
$type eq "bool" and JSON::PP::is_bool($value)
!ll&&!rl&&r
1111
MC/DC100%2/2
$type eq "bool" and JSON::PP::is_bool($value)
$type eq "bool" JSON::PP::is_bool($value)
Truth table100%3/3
A and B
A= $type eq "bool"B= JSON::PP::is_bool($value)
ABresult
0X0
100
111
41 12 ▶ if (defined($value)&&!ref($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not ref $value) 12 0 12
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0012
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
42 12 ▶ return $value if $type eq 'text';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "text" 5 7 12
43 7 ▶ return 0+$value if ($type eq 'number')&&($value=~/\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "number" and $value =~ /\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/u 0 7 7
Condition66%2/3
$type eq "number" and $value =~ /\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/u
!ll&&!rl&&r
610
MC/DC0%0/2
$type eq "number" and $value =~ /\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/u
$type eq "number" $value =~ /\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/u
Truth table66%2/3
A and B
A= $type eq "number"B= $value =~ /\A-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\z/u
ABresult
0X0
100
111
44 7 ▶ return $value if ($type eq 'special')&&($value=~/\A(?:NaN|-?Infinity)\z/);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "special" and $value =~ /\A(?:NaN|-?Infinity)\z/u 0 7 7
Condition66%2/3
$type eq "special" and $value =~ /\A(?:NaN|-?Infinity)\z/u
!ll&&!rl&&r
610
MC/DC0%0/2
$type eq "special" and $value =~ /\A(?:NaN|-?Infinity)\z/u
$type eq "special" $value =~ /\A(?:NaN|-?Infinity)\z/u
Truth table66%2/3
A and B
A= $type eq "special"B= $value =~ /\A(?:NaN|-?Infinity)\z/u
ABresult
0X0
100
111
45 7 ▶ return pack('H*', $value) if ($type eq 'bytes')&&($value=~/\A(?:[0-9a-f]{2})*\z/);
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "bytes" and $value =~ /\A(?:[0-9a-f]{2})*\z/u 1 6 7
Condition100%3/3
$type eq "bytes" and $value =~ /\A(?:[0-9a-f]{2})*\z/u
!ll&&!rl&&r
511
MC/DC100%2/2
$type eq "bytes" and $value =~ /\A(?:[0-9a-f]{2})*\z/u
$type eq "bytes" $value =~ /\A(?:[0-9a-f]{2})*\z/u
Truth table100%3/3
A and B
A= $type eq "bytes"B= $value =~ /\A(?:[0-9a-f]{2})*\z/u
ABresult
0X0
100
111
46 }
47 6 die "Invalid Hyperdrive cell value\n";
48 }
49  
50  
51 5 ▶sub result {
Subroutine result: called CC=20 SCAR=32.9
Pod undocumented
52 5 my ($result_hr)=@_;
53 5 ▶ die "Invalid Hyperdrive result\n" unless ref($result_hr) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $result_hr eq "HASH" 0 5 5
54 5 ▶ return $result_hr unless exists($result_hr->{'rows'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $result_hr->{"rows"} 1 4 5
55 4 my ($columns_ar, $rows_ar)=@{$result_hr}{qw(columns rows)};
56 4 ▶ die "Invalid Hyperdrive columns or rows\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $columns_ar eq "ARRAY" and ref $rows_ar eq "ARRAY" 0 4 4
Condition33%1/3
ref $columns_ar eq "ARRAY" and ref $rows_ar eq "ARRAY"
!ll&&!rl&&r
004
MC/DC0%0/2
ref $columns_ar eq "ARRAY" and ref $rows_ar eq "ARRAY"
ref $columns_ar eq "ARRAY" ref $rows_ar eq "ARRAY"
Truth table33%1/3
A and B
A= ref $columns_ar eq "ARRAY"B= ref $rows_ar eq "ARRAY"
ABresult
0X0
100
111
57 unless (ref($columns_ar) eq 'ARRAY')&&(ref($rows_ar) eq 'ARRAY');
58 4 foreach my $column_hr (@{$columns_ar}) {
59 die "Invalid Hyperdrive column\n" unless (ref($column_hr) eq 'HASH')
60 &&defined($column_hr->{'name'})&&!ref($column_hr->{'name'})
61 &&((defined($column_hr->{'oid'})&&!ref($column_hr->{'oid'})
62 &&($column_hr->{'oid'}=~/\A[0-9]+\z/))
63 ||(defined($column_hr->{'driver'})&&($column_hr->{'driver'} eq 'mysql')
64 &&defined($column_hr->{'type'})&&!ref($column_hr->{'type'})
65 10 ▶ &&($column_hr->{'type'}=~/\A[0-9]+\z/)));
Branch: 1 branch
BranchTrueFalseTotal
unless ref $column_hr eq "HASH" and defined $column_hr->{"name"} and not ref $column_hr->{"name"} and defined $column_hr->{"oid"} && !ref($column_hr->{"oid"}) && $column_hr->{"oid"} =~ /\A[0-9]+\z/u || defined $column_hr->{"driver"} && $column_hr->{"driver"} eq "mysql" && defined $column_hr->{"type"} && !ref($column_hr->{"type"}) && $column_hr->{"type"} =~ /\A[0-9]+\z/u 2 8 10
Condition66%20/30
ref $column_hr eq "HASH" and defined $column_hr->{"name"} and not ref $column_hr->{"name"} and defined $column_hr->{"oid"} && !ref($column_hr->{"oid"}) && $column_hr->{"oid"} =~ /\A[0-9]+\z/u || defined $column_hr->{"driver"} && $column_hr->{"driver"} eq "mysql" && defined $column_hr->{"type"} && !ref($column_hr->{"type"}) && $column_hr->{"type"} =~ /\A[0-9]+\z/u
!ll&&!rl&&r
028
ref $column_hr eq "HASH" and defined $column_hr->{"name"} and not ref $column_hr->{"name"}
!ll&&!rl&&r
0010
ref $column_hr eq "HASH" and defined $column_hr->{"name"}
!ll&&!rl&&r
0010
defined $column_hr->{"oid"} and not ref $column_hr->{"oid"} and $column_hr->{"oid"} =~ /\A[0-9]+\z/u or defined $column_hr->{"driver"} and $column_hr->{"driver"} eq "mysql" and defined $column_hr->{"type"} and not ref $column_hr->{"type"} and $column_hr->{"type"} =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
712
defined $column_hr->{"oid"} and not ref $column_hr->{"oid"} and $column_hr->{"oid"} =~ /\A[0-9]+\z/u
!ll&&!rl&&r
307
defined $column_hr->{"oid"} and not ref $column_hr->{"oid"}
!ll&&!rl&&r
307
defined $column_hr->{"driver"} and $column_hr->{"driver"} eq "mysql" and defined $column_hr->{"type"} and not ref $column_hr->{"type"} and $column_hr->{"type"} =~ /\A[0-9]+\z/u
!ll&&!rl&&r
111
defined $column_hr->{"driver"} and $column_hr->{"driver"} eq "mysql" and defined $column_hr->{"type"} and not ref $column_hr->{"type"}
!ll&&!rl&&r
102
defined $column_hr->{"driver"} and $column_hr->{"driver"} eq "mysql" and defined $column_hr->{"type"}
!ll&&!rl&&r
102
defined $column_hr->{"driver"} and $column_hr->{"driver"} eq "mysql"
!ll&&!rl&&r
102
MC/DC27%3/11
ref $column_hr eq "HASH" and defined $column_hr->{"name"} and not ref $column_hr->{"name"} and defined $column_hr->{"oid"} && !ref($column_hr->{"oid"}) && $column_hr->{"oid"} =~ /\A[0-9]+\z/u || defined $column_hr->{"driver"} && $column_hr->{"driver"} eq "mysql" && defined $column_hr->{"type"} && !ref($column_hr->{"type"}) && $column_hr->{"type"} =~ /\A[0-9]+\z/u
ref $column_hr eq "HASH" defined $column_hr->{"name"} not ref $column_hr->{"name"} defined $column_hr->{"oid"} not ref $column_hr->{"oid"} $column_hr->{"oid"} =~ /\A[0-9]+\z/u defined $column_hr->{"driver"} $column_hr->{"driver"} eq "mysql" defined $column_hr->{"type"} not ref $column_hr->{"type"} $column_hr->{"type"} =~ /\A[0-9]+\z/u
Truth table18%4/22
A and B and not(C) and D and not(E) and F or G and H and I and not(J) and K
A= ref $column_hr eq "HASH"B= defined $column_hr->{"name"}C= not ref $column_hr->{"name"}D= defined $column_hr->{"oid"}E= not ref $column_hr->{"oid"}F= $column_hr->{"oid"} =~ /\A[0-9]+\z/uG= defined $column_hr->{"driver"}H= $column_hr->{"driver"} eq "mysql"I= defined $column_hr->{"type"}J= not ref $column_hr->{"type"}K= $column_hr->{"type"} =~ /\A[0-9]+\z/u
ABCDEFGHIJKresult
0XXXXXXXXXX0
10XXXXXXXXX0
110XXXXXXXX0
1110XX0XXXX0
1110XX10XXX0
1110XX110XX0
1110XX1110X0
1110XX111100
11110X0XXXX0
11110X10XXX0
11110X110XX0
11110X1110X0
11110X111100
1111100XXXX0
11111010XXX0
111110110XX0
1111101110X0
111110111100
111111XXXXX1
1110XX111111
11110X111111
111110111111
66 }
67 2 my @rows;
68 2 foreach my $row_ar (@{$rows_ar}) {
69 2 ▶ die "Invalid Hyperdrive row\n" unless (ref($row_ar) eq 'ARRAY')&&(@{$row_ar}==@{$columns_ar});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $row_ar eq "ARRAY" and @{$row_ar;} == @{$columns_ar;} 0 2 2
Condition33%1/3
ref $row_ar eq "ARRAY" and @{$row_ar;} == @{$columns_ar;}
!ll&&!rl&&r
002
MC/DC0%0/2
ref $row_ar eq "ARRAY" and @{$row_ar;} == @{$columns_ar;}
ref $row_ar eq "ARRAY" @{$row_ar;} == @{$columns_ar;}
Truth table33%1/3
A and B
A= ref $row_ar eq "ARRAY"B= @{$row_ar;} == @{$columns_ar;}
ABresult
0X0
100
111
70 2 push(@rows, [map { cell($_) } @{$row_ar}]);
71 }
72 2 return { %{$result_hr}, rows => \@rows };
73 }
74  
75 2 1;
« blib/lib/WebDyne/Cloudflare/Hyperdrive/Transport.pm ↑ Summary lib/WebDyne/Cloudflare/DurableObject.pm »