| 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::D1; | ||||||||||||||||||||||||||||||||||||||||||
| 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_databases { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_databases: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return $self->collect_list($self->list_databases_page(%query)); | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub list_databases_page { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_databases_page: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $self->list_pagination($self->api()->account_path('d1', 'database'), | |||||||||||||||||||||||||||||||||||||||||
| 54 | { mode => 'page' }, \%query); | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub list_databases_page_response { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_databases_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | return $self->list_response($self->api()->account_path('d1', 'database'), \%query); | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub get_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($self, $id, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $self->api()->request('GET', $self->api()->account_path('d1', 'database', $id), | |||||||||||||||||||||||||||||||||||||||||
| 71 | %opt); | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub create_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_database: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my ($self, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | die "database body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | return $self->api()->request('POST', $self->api()->account_path('d1', 'database'), | |||||||||||||||||||||||||||||||||||||||||
| 81 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub delete_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_database: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my ($self, $id, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return $self->api()->request('DELETE', $self->api()->account_path('d1', 'database', $id), | |||||||||||||||||||||||||||||||||||||||||
| 90 | %opt); | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | sub update_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_database: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | my ($self, $id, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | die "database body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | return $self->api()->request('PATCH', $self->api()->account_path('d1', 'database', $id), | |||||||||||||||||||||||||||||||||||||||||
| 100 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | ▶ | sub query_database { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_database: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | # Pass SQL and its parameters in the caller's supplied request body | ||||||||||||||||||||||||||||||||||||||||||
| 109 | # | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 3 | my ($self, $id, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | ▶ | die "query body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | return $self->api()->request('POST', $self->api()->account_path('d1', 'database', $id, 'query'), | |||||||||||||||||||||||||||||||||||||||||
| 113 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub query_sql { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
query_sql: called CC=8 SCAR=22.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | # Keep bound values separate from SQL text | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | my ($self, $id, $sql, @arg)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | ▶ | my $params_ar=@arg % 2 ? shift(@arg) : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | my %opt=@arg; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | die "sql must be a non-empty scalar\n" unless defined($sql)&&!ref($sql)&&length($sql); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $sql and not ref $sql and length $sql
defined $sql and not ref $sql
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
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | die "params must be an array reference\n" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $params_ar and ref $params_ar ne "ARRAY"
MC/DC0%0/2
defined $params_ar and ref $params_ar ne "ARRAY"
defined $params_ar
ref $params_ar ne "ARRAY"
Truth table66%2/3
A and B
A= defined $params_arB= ref $params_ar ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | if defined($params_ar)&&ref($params_ar) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my %body=(sql => $sql); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | ▶ | $body{'params'}=$params_ar if defined($params_ar); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 2 | return $self->query_database($id, \%body, %opt); | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | __END__ | ||||||||||||||||||||||||||||||||||||||||||