| 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::Workers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # Compiler Pragma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use strict qw(vars); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | use vars qw(@ISA $VERSION); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # Cloudflare::API modules and inheritance | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use Cloudflare::API::Resource; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | @ISA=qw(Cloudflare::API::Resource); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # External modules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | use JSON::PP qw(encode_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use MIME::Base64 qw(encode_base64); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use Digest::SHA qw(sha256_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | ▶ | use File::Basename qw(basename); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use File::Find qw(find); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Version information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | $VERSION='1.011'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # All done. Positive return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | #============================================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 6 | ▶ | sub list_scripts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_scripts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 6 | return $self->collect_list($self->list_scripts_page(%query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 6 | ▶ | sub list_scripts_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_scripts_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 6 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $self->api()->account_path('workers', 'scripts'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | { mode => 'single' }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub list_scripts_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_scripts_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | $self->api()->account_path('workers', 'scripts'), \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub search_scripts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_scripts: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # Search uses Cloudflare's paginated script discovery endpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | return $self->collect_list($self->search_scripts_page(%query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | sub search_scripts_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_scripts_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | $self->api()->account_path('workers', 'scripts-search'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | { mode => 'page' }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub search_scripts_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
search_scripts_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | my ($self, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | $self->api()->account_path('workers', 'scripts-search'), \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | ▶ | sub get_settings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_settings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | return $self->api()->request('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | $self->api()->account_path('workers', 'scripts', $name, 'settings'), %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | sub get_script_settings { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_script_settings: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 4 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | return $self->api()->request('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | $self->api()->account_path('workers', 'scripts', $name, 'script-settings'), %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 10 | ▶ | sub inspect_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inspect_script: called CC=17 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Resolve one script summary before retrieving both kinds of settings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 10 | my $self=shift(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | ▶ | die "inspect_script selectors must be name/value pairs\n" if @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | my %selector=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | my $full_response=delete($selector{'full_response'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 9 | ▶ | die "full_response is unavailable for inspect_script\n" if $full_response; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 8 | ▶ | die "inspect_script requires exactly one of name, tag, or etag\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | unless keys(%selector)==1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | my ($selector)=keys(%selector); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 6 | ▶ | die "unknown inspect selector: $selector\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | unless $selector=~/\A(?:name|tag|etag)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | my $value=$selector{$selector}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 5 | ▶ | die "$selector must be a non-empty scalar\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $value and not ref $value and length $value
defined $value and not ref $value
MC/DC0%0/3
defined $value and not ref $value and length $value
defined $value
not ref $value
length $value
Truth table25%1/4
A and not(B) and C
A= defined $valueB= not ref $valueC= length $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | unless defined($value)&&!ref($value)&&length($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 5 | my $script_ar=$self->list_scripts(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | ▶ | die "Worker script list must be an array reference\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | unless ref($script_ar) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 5 | ▶ | my $field=$selector eq 'name' ? 'id' : $selector; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | my @match=grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 5 | ▶ | ref($_) eq 'HASH'&&defined($_->{$field})&&$_->{$field} eq $value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
ref $_ eq 'HASH' && defined $_->{$field} && $_->{$field} eq $value
ref $_ eq "HASH" and defined $_->{$field}
MC/DC33%1/3
ref $_ eq 'HASH' && defined $_->{$field} && $_->{$field} eq $value
ref $_ eq "HASH"
defined $_->{$field}
$_->{$field} eq $value
Truth table50%2/4
A and B && C
A= ref $_ eq "HASH"B= defined $_->{$field}C= $_->{$field} eq $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } @$script_ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 5 | ▶ | die "no Worker script matches $selector '$value'\n" unless @match; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 4 | ▶ | die "multiple Worker scripts match $selector '$value'\n" if @match>1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | my $name=$match[0]{'id'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | ▶ | die "matched Worker script has no name\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $name and not ref $name and length $name
defined $name and not ref $name
MC/DC0%0/3
defined $name and not ref $name and length $name
defined $name
not ref $name
length $name
Truth table25%1/4
A and not(B) and C
A= defined $nameB= not ref $nameC= length $name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | unless defined($name)&&!ref($name)&&length($name); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | script => $match[0], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | settings => $self->get_settings($name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | script_settings => $self->get_script_settings($name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | ▶ | sub download_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
download_script: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my ($self, $name)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return $self->api()->response('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | $self->api()->account_path('workers', 'scripts', $name)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 4 | ▶ | sub upload_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_script: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # Accept prepared modules; building or bundling belongs to the caller | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | my $metadata_hr=delete($opt{'metadata'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | my $files_ar=delete($opt{'files'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | my $full_response=delete($opt{'full_response'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | die "unknown upload option: $_\n" foreach sort(keys(%opt)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | my ($body, $content_type)=$self->_multipart_body($metadata_hr, $files_ar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # Uploading immediately publishes the prepared Worker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | return $self->api()->request('PUT', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | $self->api()->account_path('workers', 'scripts', $name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | content => $body, headers => { 'Content-Type' => $content_type }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | full_response => $full_response); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | sub upload_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_version: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # A version upload does not change the active deployment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 2 | my $metadata_hr=delete($opt{'metadata'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 2 | my $files_ar=delete($opt{'files'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | my $full_response=delete($opt{'full_response'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 2 | my $bindings_inherit=delete($opt{'bindings_inherit'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 2 | die "unknown upload option: $_\n" foreach sort(keys(%opt)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | ▶ | die "bindings_inherit must be strict\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $bindings_inherit and $bindings_inherit ne "strict"
MC/DC50%1/2
defined $bindings_inherit and $bindings_inherit ne "strict"
defined $bindings_inherit
$bindings_inherit ne "strict"
Truth table66%2/3
A and B
A= defined $bindings_inheritB= $bindings_inherit ne "strict"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | if defined($bindings_inherit)&&$bindings_inherit ne 'strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my ($body, $content_type)=$self->_multipart_body($metadata_hr, $files_ar); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | my %request_opt=(content => $body, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | headers => { 'Content-Type' => $content_type }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | full_response => $full_response); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | $request_opt{'query'}={ bindings_inherit => $bindings_inherit } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | if defined($bindings_inherit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return $self->api()->request('POST', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | $self->api()->account_path('workers', 'scripts', $name, 'versions'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | %request_opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 2 | ▶ | sub list_versions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_versions: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 2 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | return $self->collect_list($self->list_versions_page($name, %query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | ▶ | sub list_versions_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_versions_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 2 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 2 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | $self->api()->account_path('workers', 'scripts', $name, 'versions'), { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | mode => 'page', items => 'result.items' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | ▶ | sub list_versions_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_versions_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | $self->api()->account_path('workers', 'scripts', $name, 'versions'), \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | ▶ | sub get_version { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 1 | my ($self, $name, $version_id, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | return $self->api()->request('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | $self->api()->account_path('workers', 'scripts', $name, 'versions', $version_id), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 11 | ▶ | sub upload_assets { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
upload_assets: called CC=63 SCAR=49.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # Resolve file-backed inputs to URL paths before opening any files | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 11 | my ($self, $name, $source, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 11 | delete($opt{'full_response'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 11 | my $prefix=delete($opt{'prefix'}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 11 | die "unknown asset upload option: $_\n" foreach sort(keys(%opt)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 11 | ▶ | $prefix='' unless defined($prefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 11 | ▶ | die "invalid asset prefix\n" if ref($prefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 11 | ▶ | $prefix='/'.$prefix if length($prefix)&&$prefix!~m{\A/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $prefix and not $prefix =~ m[\A/]
MC/DC100%2/2
length $prefix and not $prefix =~ m[\A/]
length $prefix
not $prefix =~ m[\A/]
Truth table100%3/3
A and not(B)
A= length $prefixB= not $prefix =~ m[\A/]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 11 | ▶ | $prefix=~s{/\z}{} if $prefix ne '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 11 | ▶ | $prefix='' if $prefix eq '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 11 | ▶ | die "invalid asset prefix\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
length $prefix and !($prefix =~ m[\A/[A-Za-z0-9._/-]+\z]) || $prefix =~ m[(?:\A|/)\.\.? (?:/|\z)]x
not $prefix =~ m[\A/[A-Za-z0-9._/-]+\z] or $prefix =~ m[(?:\A|/)\.\.? (?:/|\z)]x
MC/DC66%2/3
length $prefix and !($prefix =~ m[\A/[A-Za-z0-9._/-]+\z]) || $prefix =~ m[(?:\A|/)\.\.? (?:/|\z)]x
length $prefix
not $prefix =~ m[\A/[A-Za-z0-9._/-]+\z]
$prefix =~ m[(?:\A|/)\.\.? (?:/|\z)]x
Truth table75%3/4
A and not(B) or C
A= length $prefixB= not $prefix =~ m[\A/[A-Za-z0-9._/-]+\z]C= $prefix =~ m[(?:\A|/)\.\.? (?:/|\z)]x
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | if length($prefix)&&($prefix!~m{\A/[A-Za-z0-9._/-]+\z}|| | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | $prefix=~m{(?:\A|/)\.\.? (?:/|\z)}x); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 10 | my %assets; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 10 | ▶ | if (ref($source) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | die "invalid asset path\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 5 | ▶ | if grep { !m{\A/[A-Za-z0-9._/-]+\z}||m{(?:\A|/)\.\.?(?:/|\z)} } keys(%$source); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
!m[\A/[A-Za-z0-9._/-]+\z] || m[(?:\A|/)\.\.?(?:/|\z)]
MC/DC0%0/2
!m[\A/[A-Za-z0-9._/-]+\z] || m[(?:\A|/)\.\.?(?:/|\z)]
!m[\A/[A-Za-z0-9._/-]+\z]
m[(?:\A|/)\.\.?(?:/|\z)]
Truth table33%1/3
not(A) || B
A= !m[\A/[A-Za-z0-9._/-]+\z]B= m[(?:\A|/)\.\.?(?:/|\z)]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 5 | %assets=%$source; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | elsif (ref($source) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 3 | foreach my $entry (@$source) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 4 | ▶ | my $item=ref($entry) eq 'HASH' ? $entry : { path => $entry }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | die "asset file path is required\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | unless ref($item) eq 'HASH'&&defined($item->{'path'})&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 4 | ▶ | !ref($item->{'path'})&&length($item->{'path'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
ref $item eq "HASH" and defined $item->{"path"} and not ref $item->{"path"} and length $item->{"path"}
ref $item eq "HASH" and defined $item->{"path"} and not ref $item->{"path"}
ref $item eq "HASH" and defined $item->{"path"}
MC/DC0%0/4
ref $item eq "HASH" and defined $item->{"path"} and not ref $item->{"path"} and length $item->{"path"}
ref $item eq "HASH"
defined $item->{"path"}
not ref $item->{"path"}
length $item->{"path"}
Truth table20%1/5
A and B and not(C) and D
A= ref $item eq "HASH"B= defined $item->{"path"}C= not ref $item->{"path"}D= length $item->{"path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 4 | ▶ | die "asset file must not be a symlink\n" if -l $item->{'path'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 4 | ▶ | die "asset file is required\n" unless -f $item->{'path'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 4 | ▶ | my $url=exists($item->{'name'}) ? $item->{'name'} : basename($item->{'path'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | ▶ | die "invalid asset name\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
defined $url and not ref $url and $url =~ m[\A[A-Za-z0-9._/-]+\z] and not $url =~ m[(?:\A|/)\.\.?(?:/|\z)]
defined $url and not ref $url and $url =~ m[\A[A-Za-z0-9._/-]+\z]
defined $url and not ref $url
MC/DC0%0/4
defined $url and not ref $url and $url =~ m[\A[A-Za-z0-9._/-]+\z] and not $url =~ m[(?:\A|/)\.\.?(?:/|\z)]
defined $url
not ref $url
$url =~ m[\A[A-Za-z0-9._/-]+\z]
not $url =~ m[(?:\A|/)\.\.?(?:/|\z)]
Truth table20%1/5
A and not(B) and C and not(D)
A= defined $urlB= not ref $urlC= $url =~ m[\A[A-Za-z0-9._/-]+\z]D= not $url =~ m[(?:\A|/)\.\.?(?:/|\z)]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | unless defined($url)&&!ref($url)&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | $url=~m{\A[A-Za-z0-9._/-]+\z}&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | $url!~m{(?:\A|/)\.\.?(?:/|\z)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | my $path='/'.$url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 4 | ▶ | die "duplicate asset path: $path\n" if exists($assets{$path}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 3 | $assets{$path}=$item; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ▶ | elsif (defined($source)&&!ref($source)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $source and not ref $source
MC/DC0%0/2
defined $source and not ref $source
defined $source
not ref $source
Truth table33%1/3
A and not(B)
A= defined $sourceB= not ref $source
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | ▶ | die "asset directory must not be a symlink\n" if -l $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | die "asset directory is required\n" unless -d $source; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 2 | my $root=File::Spec->rel2abs($source); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 9 | ▶ | find({ no_chdir => 1, wanted => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 9 | my $file=$File::Find::name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 9 | ▶ | die "asset directory contains a symlink: $file\n" if -l $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 8 | ▶ | return if -d $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 4 | ▶ | die "asset directory contains a non-file: $file\n" unless -f $file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 4 | my $relative=File::Spec->abs2rel($file, $root); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 4 | my $path='/'.$relative; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 4 | ▶ | die "duplicate asset path: $path\n" if exists($assets{$path}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 4 | $assets{$path}={ path => $file }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | } }, $root); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | die "assets must be a directory, array reference, or hash reference\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 8 | ▶ | die "assets must not be empty\n" unless keys(%assets); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | # Register a prepared asset set and upload only hashes Cloudflare needs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 7 | my (%manifest, %content, %content_type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 7 | foreach my $name (sort(keys(%assets))) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 15 | my $path=$prefix.$name; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 15 | ▶ | die "invalid asset path\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$path =~ m[\A/[A-Za-z0-9._/-]+\z] and not $path =~ m[(?:\A|/)\.\.?(?:/|\z)]
MC/DC0%0/2
$path =~ m[\A/[A-Za-z0-9._/-]+\z] and not $path =~ m[(?:\A|/)\.\.?(?:/|\z)]
$path =~ m[\A/[A-Za-z0-9._/-]+\z]
not $path =~ m[(?:\A|/)\.\.?(?:/|\z)]
Truth table33%1/3
A and not(B)
A= $path =~ m[\A/[A-Za-z0-9._/-]+\z]B= not $path =~ m[(?:\A|/)\.\.?(?:/|\z)]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | unless $path=~m{\A/[A-Za-z0-9._/-]+\z}&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | $path!~m{(?:\A|/)\.\.?(?:/|\z)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 15 | my $item=$assets{$name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 15 | my $bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | my $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 15 | ▶ | if (ref($item) eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 8 | $type=$item->{'content_type'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 8 | ▶ | die "asset path is required\n" unless defined($item->{'path'})&&!ref($item->{'path'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $item->{"path"} and not ref $item->{"path"}
MC/DC0%0/2
defined $item->{"path"} and not ref $item->{"path"}
defined $item->{"path"}
not ref $item->{"path"}
Truth table33%1/3
A and not(B)
A= defined $item->{"path"}B= not ref $item->{"path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 8 | ▶ | open(my $asset_fh, '<', $item->{'path'}) || die "unable to open asset: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 8 | ▶ | binmode($asset_fh) || die "unable to set binary mode on asset: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 8 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 8 | $bytes=<$asset_fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 8 | ▶ | close($asset_fh) || die "unable to close asset: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 7 | ▶ | die "asset content must be a scalar\n" unless defined($item)&&!ref($item); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $item and not ref $item
MC/DC0%0/2
defined $item and not ref $item
defined $item
not ref $item
Truth table33%1/3
A and not(B)
A= defined $itemB= not ref $item
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 7 | $bytes="$item"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 7 | ▶ | utf8::encode($bytes) if utf8::is_utf8($bytes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 15 | my ($extension)=$path=~/\.([^.\/]*)\z/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 15 | ▶ | $extension='' unless defined($extension); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 15 | $extension=lc($extension); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 15 | ▶ | $type=$self->asset_content_type($extension) unless defined($type); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 15 | ▶ | die "invalid asset content type\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $type and not ref $type and $type =~ m[\A[A-Za-z0-9!#\$&^_.+-]+/[A-Za-z0-9!#\$&^_.+-]+\z]
defined $type and not ref $type
MC/DC33%1/3
defined $type and not ref $type and $type =~ m[\A[A-Za-z0-9!#\$&^_.+-]+/[A-Za-z0-9!#\$&^_.+-]+\z]
defined $type
not ref $type
$type =~ m[\A[A-Za-z0-9!#\$&^_.+-]+/[A-Za-z0-9!#\$&^_.+-]+\z]
Truth table50%2/4
A and not(B) and C
A= defined $typeB= not ref $typeC= $type =~ m[\A[A-Za-z0-9!#\$&^_.+-]+/[A-Za-z0-9!#\$&^_.+-]+\z]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | unless defined($type)&&!ref($type)&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | $type=~m{\A[A-Za-z0-9!#\$&^_.+-]+/[A-Za-z0-9!#\$&^_.+-]+\z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 14 | my $hash=substr(sha256_hex(encode_base64($bytes, '').$extension), 0, 32); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 14 | $manifest{$path}={ hash => $hash, size => length($bytes) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 14 | $content{$hash}=encode_base64($bytes, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 14 | $content_type{$hash}=$type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 6 | my $session_hr=$self->api()->request('POST', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | $self->api()->account_path('workers', 'scripts', $name, 'assets-upload-session'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | json => { manifest => \%manifest }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | die "asset upload session is incomplete\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | unless ref($session_hr) eq 'HASH'&&ref($session_hr->{'buckets'}) eq 'ARRAY'&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 6 | ▶ | defined($session_hr->{'jwt'})&&!ref($session_hr->{'jwt'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
ref $session_hr eq "HASH" and ref $session_hr->{"buckets"} eq "ARRAY" and defined $session_hr->{"jwt"} and not ref $session_hr->{"jwt"}
ref $session_hr eq "HASH" and ref $session_hr->{"buckets"} eq "ARRAY" and defined $session_hr->{"jwt"}
ref $session_hr eq "HASH" and ref $session_hr->{"buckets"} eq "ARRAY"
MC/DC0%0/4
ref $session_hr eq "HASH" and ref $session_hr->{"buckets"} eq "ARRAY" and defined $session_hr->{"jwt"} and not ref $session_hr->{"jwt"}
ref $session_hr eq "HASH"
ref $session_hr->{"buckets"} eq "ARRAY"
defined $session_hr->{"jwt"}
not ref $session_hr->{"jwt"}
Truth table20%1/5
A and B and C and not(D)
A= ref $session_hr eq "HASH"B= ref $session_hr->{"buckets"} eq "ARRAY"C= defined $session_hr->{"jwt"}D= not ref $session_hr->{"jwt"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 6 | my $completion_jwt=$session_hr->{'jwt'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 6 | ▶ | $completion_jwt=undef if @{$session_hr->{'buckets'}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 6 | foreach my $bucket_ar (@{$session_hr->{'buckets'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 5 | ▶ | die "invalid asset upload bucket\n" unless ref($bucket_ar) eq 'ARRAY'&&@$bucket_ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $bucket_ar eq "ARRAY" and @$bucket_ar
MC/DC0%0/2
ref $bucket_ar eq "ARRAY" and @$bucket_ar
ref $bucket_ar eq "ARRAY"
@$bucket_ar
Truth table33%1/3
A and B
A= ref $bucket_ar eq "ARRAY"B= @$bucket_ar
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 5 | my $boundary=sprintf('cloudflare-api-%x-%x-%x', time(), $$, int(rand(0x7fffffff))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 5 | my $body=''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 5 | foreach my $hash (@$bucket_ar) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 13 | ▶ | die "unknown asset hash in upload session\n" unless exists($content{$hash}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | $body.='--'.$boundary."\r\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 'Content-Disposition: form-data; name="'.$hash.'"'."\r\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 'Content-Type: '.$content_type{$hash}."\r\n\r\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 13 | $content{$hash}."\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 5 | $body.='--'.$boundary."--\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | my $result_hr=$self->api()->request('POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | $self->api()->account_path('workers', 'assets', 'upload'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | query => { base64 => 'true' }, content => $body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 5 | headers => { Authorization => 'Bearer '.$session_hr->{'jwt'}, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 'Content-Type' => 'multipart/form-data; boundary='.$boundary }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 5 | ▶ | $completion_jwt=$result_hr->{'jwt'} if defined($result_hr->{'jwt'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 6 | ▶ | die "asset upload did not return a completion token\n" unless defined($completion_jwt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 6 | return { jwt => $completion_jwt, manifest => \%manifest }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 12 | ▶ | sub asset_content_type { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
asset_content_type: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | # Cloudflare serves the MIME type supplied with each asset part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 12 | my ($self, $extension)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 12 | my %type=( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | html => 'text/html', htm => 'text/html', css => 'text/css', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | js => 'text/javascript', mjs => 'text/javascript', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | json => 'application/json', webmanifest => 'application/manifest+json', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | txt => 'text/plain', xml => 'application/xml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | svg => 'image/svg+xml', png => 'image/png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | jpg => 'image/jpeg', jpeg => 'image/jpeg', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | gif => 'image/gif', webp => 'image/webp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | avif => 'image/avif', ico => 'image/x-icon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | woff => 'font/woff', woff2 => 'font/woff2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | pdf => 'application/pdf', wasm => 'application/wasm' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 12 | ▶ | return $type{$extension} || 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$type{$extension} || 'application/octet-stream'
MC/DC0%0/1
$type{$extension} || 'application/octet-stream'
$type{$extension}
Truth table50%1/2
A
A= $type{$extension}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 5 | ▶ | sub _multipart_body { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_multipart_body: called CC=31 SCAR=41.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 5 | my ($self, $metadata_hr, $files_ar)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 5 | ▶ | die "metadata must be a hash reference\n" unless ref($metadata_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 5 | ▶ | die "files must be a non-empty array reference\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $files_ar eq "ARRAY" and @$files_ar
MC/DC0%0/2
ref $files_ar eq "ARRAY" and @$files_ar
ref $files_ar eq "ARRAY"
@$files_ar
Truth table33%1/3
A and B
A= ref $files_ar eq "ARRAY"B= @$files_ar
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | unless ref($files_ar) eq 'ARRAY'&&@$files_ar; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | # Cloudflare requires the entry point to match an uploaded file name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 5 | my $main_module=$metadata_hr->{'main_module'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 5 | ▶ | die "metadata main_module is required\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $main_module and not ref $main_module and length $main_module
defined $main_module and not ref $main_module
MC/DC0%0/3
defined $main_module and not ref $main_module and length $main_module
defined $main_module
not ref $main_module
length $main_module
Truth table25%1/4
A and not(B) and C
A= defined $main_moduleB= not ref $main_moduleC= length $main_module
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | unless defined($main_module)&&!ref($main_module)&&length($main_module); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Validate each multipart file and read any file-backed content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 5 | my @part; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | my %name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 5 | foreach my $file_hr (@$files_ar) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 5 | ▶ | die "each file must be a hash reference\n" unless ref($file_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 5 | my $part_name=$file_hr->{'name'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 5 | ▶ | die "invalid file name\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
defined $part_name and not ref $part_name and $part_name =~ m[\A[A-Za-z0-9._/-]+\z] and not $part_name =~ m[\A/|(?:\A|/)\.\.(?:/|\z)]
defined $part_name and not ref $part_name and $part_name =~ m[\A[A-Za-z0-9._/-]+\z]
defined $part_name and not ref $part_name
MC/DC25%1/4
defined $part_name and not ref $part_name and $part_name =~ m[\A[A-Za-z0-9._/-]+\z] and not $part_name =~ m[\A/|(?:\A|/)\.\.(?:/|\z)]
defined $part_name
not ref $part_name
$part_name =~ m[\A[A-Za-z0-9._/-]+\z]
not $part_name =~ m[\A/|(?:\A|/)\.\.(?:/|\z)]
Truth table40%2/5
A and not(B) and C and not(D)
A= defined $part_nameB= not ref $part_nameC= $part_name =~ m[\A[A-Za-z0-9._/-]+\z]D= not $part_name =~ m[\A/|(?:\A|/)\.\.(?:/|\z)]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | unless defined($part_name)&&!ref($part_name)&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | $part_name=~/\A[A-Za-z0-9._\/-]+\z/&& | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | $part_name!~m{\A/|(?:\A|/)\.\.(?:/|\z)}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 4 | ▶ | die "duplicate file name: $part_name\n" if $name{$part_name}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | my $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 4 | ▶ | if (exists($file_hr->{'path'})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | die "file content and path are mutually exclusive\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 1 | ▶ | if exists($file_hr->{'content'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 1 | my $path_fn=$file_hr->{'path'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 1 | ▶ | die "file path must be a non-empty scalar\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $path_fn and not ref $path_fn and length $path_fn
defined $path_fn and not ref $path_fn
MC/DC0%0/3
defined $path_fn and not ref $path_fn and length $path_fn
defined $path_fn
not ref $path_fn
length $path_fn
Truth table25%1/4
A and not(B) and C
A= defined $path_fnB= not ref $path_fnC= length $path_fn
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | unless defined($path_fn)&&!ref($path_fn)&&length($path_fn); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 1 | ▶ | open(my $file_fh, '<', $path_fn) || die "unable to open $path_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 1 | ▶ | binmode($file_fh) || die "unable to set binary mode on $path_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 1 | local $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 1 | $content=<$file_fh>; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 1 | ▶ | close($file_fh) || die "unable to close $path_fn: $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 3 | $content=$file_hr->{'content'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 4 | ▶ | die "file content must be a scalar\n" unless defined($content)&&!ref($content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $content and not ref $content
MC/DC0%0/2
defined $content and not ref $content
defined $content
not ref $content
Truth table33%1/3
A and not(B)
A= defined $contentB= not ref $content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | ▶ | utf8::encode($content) if utf8::is_utf8($content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 4 | ▶ | my $content_type=$file_hr->{'content_type'} || 'application/javascript+module'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$file_hr->{'content_type'} || 'application/javascript+module'
MC/DC0%0/1
$file_hr->{'content_type'} || 'application/javascript+module'
$file_hr->{'content_type'}
Truth table50%1/2
A
A= $file_hr->{'content_type'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | ▶ | die "invalid content type\n" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | unless $content_type=~m{\A[A-Za-z0-9.+-]+/[A-Za-z0-9.+-]+\z}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 4 | push(@part, [$part_name, $content_type, $content]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 4 | ▶ | die "main_module must match an uploaded file name\n" unless $name{$main_module}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | # Choose a boundary absent from the metadata and all module content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 3 | my $metadata=encode_json($metadata_hr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 3 | my $boundary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 3 | $boundary=sprintf('cloudflare-api-%x-%x-%x', time(), $$, int(rand(0x7fffffff))); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | } while index($metadata, $boundary)>=0 || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 3 | ▶ | grep { index($_->[2], $boundary)>=0 } @part; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
index($metadata, $boundary) != -1 or grep {index($_->[2], $boundary) != -1;} @part
MC/DC0%0/2
index($metadata, $boundary) != -1 or grep {index($_->[2], $boundary) != -1;} @part
index($metadata, $boundary) != -1
grep {index($_->[2], $boundary) != -1;} @part
Truth table33%1/3
A or B
A= index($metadata, $boundary) != -1B= grep {index($_->[2], $boundary) != -1;} @part
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # Assemble the multipart body exactly as the upload endpoint expects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 3 | my $body='--'.$boundary."\r\n". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | "Content-Disposition: form-data; name=\"metadata\"\r\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | "Content-Type: application/json\r\n\r\n".$metadata."\r\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 3 | foreach my $part_ar (@part) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 3 | $body.='--'.$boundary."\r\n". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 'Content-Disposition: form-data; name="'.$part_ar->[0].'"; filename="'.$part_ar->[0]."\"\r\n". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 'Content-Type: '.$part_ar->[1]."\r\n\r\n".$part_ar->[2]."\r\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 3 | $body.='--'.$boundary."--\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 3 | return ($body, 'multipart/form-data; boundary='.$boundary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | ▶ | sub delete_script { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_script: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | return $self->api()->request('DELETE', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | $self->api()->account_path('workers', 'scripts', $name), %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | ▶ | sub list_deployments { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_deployments: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | return $self->collect_list($self->list_deployments_page($name, %query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | sub list_deployments_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_deployments_page: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | $self->api()->account_path('workers', 'scripts', $name, 'deployments'), { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | mode => 'page', items => 'result.deployments' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | sub list_deployments_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_deployments_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | $self->api()->account_path('workers', 'scripts', $name, 'deployments'), \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 1 | ▶ | sub create_deployment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_deployment: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 1 | my ($self, $name, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 1 | ▶ | die "deployment body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 1 | return $self->api()->request('POST', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | $self->api()->account_path('workers', 'scripts', $name, 'deployments'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | ▶ | sub get_deployment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_deployment: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 1 | my ($self, $name, $deployment_id, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | return $self->api()->request('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | $self->api()->account_path('workers', 'scripts', $name, 'deployments', $deployment_id), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 1 | ▶ | sub list_secrets { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_secrets: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 1 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | return $self->collect_list($self->list_secrets_page($name, %query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 1 | ▶ | sub list_secrets_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_secrets_page: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | $self->api()->account_path('workers', 'scripts', $name, 'secrets'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | { mode => 'single' }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | sub list_secrets_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_secrets_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | my ($self, $name, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | $self->api()->account_path('workers', 'scripts', $name, 'secrets'), \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | ▶ | sub add_secret { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_secret: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 1 | my ($self, $name, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | ▶ | die "secret body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 1 | return $self->api()->request('PUT', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | $self->api()->account_path('workers', 'scripts', $name, 'secrets'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 1 | ▶ | sub delete_secret { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_secret: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 1 | my ($self, $name, $secret_name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 1 | return $self->api()->request('DELETE', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | $self->api()->account_path('workers', 'scripts', $name, 'secrets', $secret_name), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | sub get_subdomain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_subdomain: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 0 | my ($self, $name, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | return $self->api()->request('GET', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | $self->api()->account_path('workers', 'scripts', $name, 'subdomain'), %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 1 | ▶ | sub set_subdomain { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_subdomain: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | my ($self, $name, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 1 | ▶ | die "subdomain body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 1 | return $self->api()->request('POST', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | $self->api()->account_path('workers', 'scripts', $name, 'subdomain'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | sub list_routes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_routes: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | # Worker routes are zone-scoped, unlike the account-scoped script calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | my ($self, $zone_id, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | return $self->collect_list($self->list_routes_page($zone_id, %query)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | ▶ | sub list_routes_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_routes_page: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | my ($self, $zone_id, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 0 | return $self->list_pagination( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | '/zones/'.$self->api()->segment($zone_id).'/workers/routes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | { mode => 'single' }, \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | ▶ | sub list_routes_page_response { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_routes_page_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 0 | my ($self, $zone_id, %query)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 0 | return $self->list_response( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | '/zones/'.$self->api()->segment($zone_id).'/workers/routes', \%query); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 1 | ▶ | sub create_route { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_route: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 1 | my ($self, $zone_id, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 1 | ▶ | die "route body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 1 | return $self->api()->request('POST', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | '/zones/'.$self->api()->segment($zone_id).'/workers/routes', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 1 | ▶ | sub update_route { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_route: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 1 | my ($self, $zone_id, $route_id, $body_hr, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 1 | ▶ | die "route body must be a hash reference\n" unless ref($body_hr) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 1 | return $self->api()->request('PUT', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | '/zones/'.$self->api()->segment($zone_id).'/workers/routes/'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | $self->api()->segment($route_id), json => $body_hr, %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | ▶ | sub delete_route { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
delete_route: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | my ($self, $zone_id, $route_id, %opt)=@_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | return $self->api()->request('DELETE', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | '/zones/'.$self->api()->segment($zone_id).'/workers/routes/'. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | $self->api()->segment($route_id), %opt); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||