blib/lib/Cloudflare/API/KV.pm

filter: Statementstmt 77.7% 42 / 54 Branchbran 66.6% 8 / 12 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 64.7% 11 / 17 Podpod 0.0% 0 / 13 totaltotal 61.3% 65 / 106 CC 12 SCAR 14.4
CC
12
Cov
74%
put_value
9.7
create_namespace
2.0
rename_namespace
2.0
CRAP 4.2
« blib/lib/Cloudflare/API/D1.pm ↑ Summary blib/lib/Cloudflare/API/Hyperdrive.pm »
1 #
2 # This file is part of Cloudflare::API.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package Cloudflare::API::KV;
14  
15  
16 # Compiler Pragma
17 #
18 1 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # Cloudflare::API modules and inheritance
24 #
25 1 ▶use Cloudflare::API::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 @ISA=qw(Cloudflare::API::Resource);
27  
28  
29 # Version information
30 #
31 1 $VERSION='1.011';
32  
33  
34 # All done. Positive return
35 #
36 1 1;
37  
38  
39 #============================================================================
40  
41  
42 0 ▶sub list_namespaces {
Subroutine list_namespaces: not called CC=1 SCAR=6.9
Pod undocumented
43  
44 0 my ($self, %query)=@_;
45 0 return $self->collect_list($self->list_namespaces_page(%query));
46  
47 }
48  
49  
50 0 ▶sub list_namespaces_page {
Subroutine list_namespaces_page: not called CC=1 SCAR=6.9
Pod undocumented
51  
52 0 my ($self, %query)=@_;
53 0 return $self->list_pagination(
54 $self->api()->account_path('storage', 'kv', 'namespaces'),
55 { mode => 'page' }, \%query);
56  
57 }
58  
59  
60 0 ▶sub list_namespaces_page_response {
Subroutine list_namespaces_page_response: not called CC=1 SCAR=6.9
Pod undocumented
61  
62 0 my ($self, %query)=@_;
63 0 return $self->list_response(
64 $self->api()->account_path('storage', 'kv', 'namespaces'), \%query);
65  
66 }
67  
68  
69 0 ▶sub get_namespace {
Subroutine get_namespace: not called CC=1 SCAR=6.9
Pod undocumented
70  
71 0 my ($self, $id, %opt)=@_;
72 0 return $self->api()->request('GET', $self->api()->account_path('storage', 'kv', 'namespaces', $id),
73 %opt);
74  
75 }
76  
77  
78 1 ▶sub create_namespace {
Subroutine create_namespace: called CC=2 SCAR=7.1
Pod undocumented
79  
80  
81 # Forward the namespace body after checking its expected shape
82 #
83 1 my ($self, $body_hr, %opt)=@_;
84 1 ▶ die "namespace body must be a hash reference\n" unless ref($body_hr) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $body_hr eq "HASH" 0 1 1
85 1 return $self->api()->request('POST', $self->api()->account_path('storage', 'kv', 'namespaces'),
86 json => $body_hr, %opt);
87  
88 }
89  
90  
91 1 ▶sub rename_namespace {
Subroutine rename_namespace: called CC=2 SCAR=7.1
Pod undocumented
92  
93 1 my ($self, $id, $body_hr, %opt)=@_;
94 1 ▶ die "namespace body must be a hash reference\n" unless ref($body_hr) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $body_hr eq "HASH" 0 1 1
95 1 return $self->api()->request('PUT', $self->api()->account_path('storage', 'kv', 'namespaces', $id),
96 json => $body_hr, %opt);
97  
98 }
99  
100  
101 0 ▶sub delete_namespace {
Subroutine delete_namespace: not called CC=1 SCAR=6.9
Pod undocumented
102  
103 0 my ($self, $id, %opt)=@_;
104 0 return $self->api()->request('DELETE', $self->api()->account_path('storage', 'kv', 'namespaces', $id),
105 %opt);
106  
107 }
108  
109  
110 1 ▶sub list_keys {
Subroutine list_keys: called CC=1 SCAR=0.0
Pod undocumented
111  
112 1 my ($self, $id, %query)=@_;
113 1 return $self->collect_list($self->list_keys_page($id, %query));
114  
115 }
116  
117  
118 1 ▶sub list_keys_page {
Subroutine list_keys_page: called CC=1 SCAR=0.0
Pod undocumented
119  
120 1 my ($self, $id, %query)=@_;
121 1 return $self->list_pagination(
122 $self->api()->account_path('storage', 'kv', 'namespaces', $id, 'keys'), {
123 mode => 'cursor', page_size_param => 'limit'
124 }, \%query);
125  
126 }
127  
128  
129 0 ▶sub list_keys_page_response {
Subroutine list_keys_page_response: not called CC=1 SCAR=6.9
Pod undocumented
130  
131 0 my ($self, $id, %query)=@_;
132 0 return $self->list_response(
133 $self->api()->account_path('storage', 'kv', 'namespaces', $id, 'keys'), \%query);
134  
135 }
136  
137  
138 1 ▶sub get_value {
Subroutine get_value: called CC=2 SCAR=6.9
Pod undocumented
139  
140  
141 # KV values are bytes rather than Cloudflare JSON envelopes
142 #
143 1 my ($self, $id, $key, %opt)=@_;
144 1 delete($opt{'full_response'});
145 1 die "unknown get option: $_\n" foreach sort(keys(%opt));
146 1 my $response_or=$self->api()->response('GET',
147 $self->api()->account_path('storage', 'kv', 'namespaces', $id, 'values', $key));
148 1 return $response_or->content();
149  
150 }
151  
152  
153 2 ▶sub put_value {
Subroutine put_value: called CC=9 SCAR=22.8
Pod undocumented
154  
155  
156 # A plain request body preserves arbitrary value bytes
157 #
158 2 my ($self, $id, $key, $value, %opt)=@_;
159 2 ▶ die "value must be a scalar\n" unless defined($value)&&!ref($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 2 2
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
002
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
160 2 my $full_response=delete($opt{'full_response'});
161 2 my %query;
162 2 foreach my $name (qw(expiration expiration_ttl)) {
163 4 ▶ $query{$name}=delete($opt{$name}) if exists($opt{$name});
Branch: 1 branch
BranchTrueFalseTotal
if exists $opt{$name} 3 1 4
164 }
165 2 die "unknown put option: $_\n" foreach sort(keys(%opt));
166 die "expiration and expiration_ttl are mutually exclusive\n"
167 2 ▶ if exists($query{'expiration'})&&exists($query{'expiration_ttl'});
Branch: 1 branch
BranchTrueFalseTotal
if exists $query{"expiration"} and exists $query{"expiration_ttl"} 1 1 2
Condition66%2/3
exists $query{"expiration"} and exists $query{"expiration_ttl"}
!ll&&!rl&&r
101
MC/DC50%1/2
exists $query{"expiration"} and exists $query{"expiration_ttl"}
exists $query{"expiration"} exists $query{"expiration_ttl"}
Truth table66%2/3
A and B
A= exists $query{"expiration"}B= exists $query{"expiration_ttl"}
ABresult
0X0
100
111
168 1 ▶ utf8::encode($value) if utf8::is_utf8($value);
Branch: 1 branch
BranchTrueFalseTotal
if utf8::is_utf8($value) 0 1 1
169 1 return $self->api()->request('PUT',
170 $self->api()->account_path('storage', 'kv', 'namespaces', $id, 'values', $key),
171 content => $value, headers => { 'Content-Type' => 'application/octet-stream' },
172 query => \%query, full_response => $full_response);
173  
174 }
175  
176  
177 1 ▶sub delete_value {
Subroutine delete_value: called CC=1 SCAR=0.0
Pod undocumented
178  
179 1 my ($self, $id, $key, %opt)=@_;
180 1 return $self->api()->request('DELETE',
181 $self->api()->account_path('storage', 'kv', 'namespaces', $id, 'values', $key), %opt);
182  
183 }
184 __END__
« blib/lib/Cloudflare/API/D1.pm ↑ Summary blib/lib/Cloudflare/API/Hyperdrive.pm »