Sheets/Client.pm

filter: Statementstmt 97.1% 170 / 175 Branchbran 90.0% 54 / 60 Conditioncond 70.1% 47 / 67 MC/DCmcdc 43.2% 16 / 37 Subroutinesub 97.1% 34 / 35 Podpod 86.6% 13 / 15 totaltotal 85.8% 334 / 389 CC 64 SCAR 18.2
CC
64
Cov
90%
BUILDARGS
16.5
_request
9.0
_access_token
8.4
CRAP 6.2
↑ Summary Sheets/Worksheet.pm »
1 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 3 ▶use v5.42;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 package Tie::Google::Sheets::Client 0.02 {
5  
6 # ABSTRACT: Low level client used internally by Tie::Google::Sheets
7  
8 3 ▶ use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶ use JSON::MaybeXS qw( decode_json encode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶ use HTTP::AnyUA;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶ use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶ use URI::Escape qw( uri_escape );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶ use Crypt::JWT qw( encode_jwt );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶ use Ref::Util qw( is_ref is_plain_hashref is_plain_coderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶ use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 3 our @CARP_NOT = qw( Tie::Google::Sheets Tie::Google::Sheets::Worksheet Class::Tiny::Object );
18  
19 3 ▶ use Class::Tiny qw( spreadsheet_id ua access_token service_account ), {
Subroutine BEGIN: called CC=1 SCAR=0.0
20 token => undef,
21 token_expires => 0,
22 batch_size => undef,
23 backoff_retry => undef,
24 18 ▶ _pending => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 3 };
26  
27 0 ▶ our $SLEEP = sub ($seconds) { sleep $seconds };
Subroutine __ANON__: not called CC=1 SCAR=1.2
28  
29 3 ▶ use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
30 3 API_BASE => 'https://sheets.googleapis.com/v4/spreadsheets',
31 TOKEN_URI => 'https://oauth2.googleapis.com/token',
32 SCOPE => 'https://www.googleapis.com/auth/spreadsheets',
33 3 };
34  
35 28 ▶ sub BUILDARGS ($class, %args) {
Subroutine BUILDARGS: called CC=16 SCAR=28.0
Pod undocumented
36 28 my $spreadsheet_id = delete $args{spreadsheet_id};
37 28 my $spreadsheet_url = delete $args{spreadsheet_url};
38 28 ▶ if(!defined $spreadsheet_id && defined $spreadsheet_url) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $spreadsheet_id and defined $spreadsheet_url) 0 28 28
Condition66%2/3
not defined $spreadsheet_id and defined $spreadsheet_url
!ll&&!rl&&r
2710
MC/DC0%0/2
not defined $spreadsheet_id and defined $spreadsheet_url
not defined $spreadsheet_id defined $spreadsheet_url
Truth table66%2/3
not(A) and B
A= not defined $spreadsheet_idB= defined $spreadsheet_url
ABresult
0X0
100
111
39 0 ($spreadsheet_id) = $spreadsheet_url =~ m{/d/([a-zA-Z0-9_-]+)};
40 }
41 28 ▶ croak 'spreadsheet_id (or a recognizable spreadsheet_url) is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $spreadsheet_id 1 27 28
42 unless defined $spreadsheet_id;
43  
44 27 my $service_account = delete $args{service_account};
45 27 my $access_token = delete $args{access_token};
46 27 ▶ croak 'one of service_account or access_token is required'
Branch: 1 branch
BranchTrueFalseTotal
unless defined $service_account or defined $access_token 1 26 27
Condition100%3/3
defined $service_account or defined $access_token
l!l&&r!l&&!r
3231
MC/DC100%2/2
defined $service_account or defined $access_token
defined $service_account defined $access_token
Truth table100%3/3
A or B
A= defined $service_accountB= defined $access_token
ABresult
1X1
011
000
47 unless defined $service_account || defined $access_token;
48  
49 26 my $ua_arg = delete $args{ua};
50 26 my $any_ua_arg = delete $args{any_ua};
51 26 ▶ croak 'only one of ua or any_ua may be given' if defined $ua_arg && defined $any_ua_arg;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ua_arg and defined $any_ua_arg 1 25 26
Condition66%2/3
defined $ua_arg and defined $any_ua_arg
!ll&&!rl&&r
2501
MC/DC50%1/2
defined $ua_arg and defined $any_ua_arg
defined $ua_arg defined $any_ua_arg
Truth table66%2/3
A and B
A= defined $ua_argB= defined $any_ua_arg
ABresult
0X0
100
111
52  
53 25 my $batch_size = delete $args{batch_size};
54 25 ▶ croak 'batch_size must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
if defined $batch_size and not $batch_size =~ /\A[1-9][0-9]*\z/u 3 22 25
Condition100%3/3
defined $batch_size and not $batch_size =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
2023
MC/DC100%2/2
defined $batch_size and not $batch_size =~ /\A[1-9][0-9]*\z/u
defined $batch_size not $batch_size =~ /\A[1-9][0-9]*\z/u
Truth table100%3/3
A and not(B)
A= defined $batch_sizeB= not $batch_size =~ /\A[1-9][0-9]*\z/u
ABresult
0X0
100
111
55 if defined $batch_size && $batch_size !~ /\A[1-9][0-9]*\z/;
56  
57 22 my $backoff_retry = delete $args{backoff_retry};
58 22 ▶ croak 'backoff_retry must be a positive integer'
Branch: 1 branch
BranchTrueFalseTotal
if defined $backoff_retry and not $backoff_retry =~ /\A[1-9][0-9]*\z/u 1 21 22
Condition100%3/3
defined $backoff_retry and not $backoff_retry =~ /\A[1-9][0-9]*\z/u
!ll&&!rl&&r
1831
MC/DC100%2/2
defined $backoff_retry and not $backoff_retry =~ /\A[1-9][0-9]*\z/u
defined $backoff_retry not $backoff_retry =~ /\A[1-9][0-9]*\z/u
Truth table100%3/3
A and not(B)
A= defined $backoff_retryB= not $backoff_retry =~ /\A[1-9][0-9]*\z/u
ABresult
0X0
100
111
59 if defined $backoff_retry && $backoff_retry !~ /\A[1-9][0-9]*\z/;
60  
61 21 ▶ croak "unknown constructor argument(s): @{[ sort keys %args ]}" if %args;
Branch: 1 branch
BranchTrueFalseTotal
if %args 1 20 21
62  
63 20 ▶ my $ua = $any_ua_arg // HTTP::AnyUA->new( ua => $ua_arg // do {
Condition50%3/6
$any_ua_arg // "HTTP::AnyUA"->new("ua", $ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new })
l!l&&r!l&&!r
1820
$ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new }
l!l&&r!l&&!r
020
MC/DC0%0/2
$any_ua_arg // "HTTP::AnyUA"->new("ua", $ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new })
$any_ua_arg "HTTP::AnyUA"->new("ua", $ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new })
MC/DC0%0/2
$ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new }
$ua_arg do { require HTTP::Tiny; "HTTP::Tiny"->new }
Truth table66%2/3
A // B
A= $any_ua_argB= "HTTP::AnyUA"->new("ua", $ua_arg // do { require HTTP::Tiny; "HTTP::Tiny"->new })
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $ua_argB= do { require HTTP::Tiny; "HTTP::Tiny"->new }
ABresult
1X1
011
000
64 2 require HTTP::Tiny;
65 2 HTTP::Tiny->new
66 });
67  
68 return {
69 20 ▶ spreadsheet_id => $spreadsheet_id,
Branch: 1 branch
BranchTrueFalseTotal
defined $service_account ? : 3 17 20
70 ua => $ua,
71 access_token => $access_token,
72 service_account => defined $service_account
73 ? $class->_load_service_account($service_account)
74 : undef,
75 batch_size => $batch_size,
76 backoff_retry => $backoff_retry,
77 };
78 }
79  
80 3 ▶ sub _load_service_account ($class, $val) {
Subroutine _load_service_account: called CC=4 SCAR=14.0
81 3 ▶ return $val if is_plain_hashref($val);
Branch: 1 branch
BranchTrueFalseTotal
if is_plain_hashref($val) 1 2 3
82 2 ▶ croak 'service_account must be a hashref of the decoded key file, or a path to one'
Branch: 1 branch
BranchTrueFalseTotal
unless not is_ref($val) and path($val)->is_file 1 1 2
Condition66%2/3
not is_ref($val) and path($val)->is_file
!ll&&!rl&&r
101
MC/DC50%1/2
not is_ref($val) and path($val)->is_file
not is_ref($val) path($val)->is_file
Truth table66%2/3
not(A) and B
A= not is_ref($val)B= path($val)->is_file
ABresult
0X0
100
111
83 unless !is_ref($val) && path($val)->is_file;
84  
85 1 my $json;
86 1 try { $json = path($val)->slurp_raw }
87 1 catch ($e) { croak "unable to open service account key file $val: $!" }
88  
89 0 return decode_json($json);
90 }
91  
92 102 ▶ sub _access_token ($self) {
Subroutine _access_token: called CC=8 SCAR=21.2
93 102 ▶ if(defined(my $token = $self->access_token)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $token = $self->access_token)) 99 3 102
94 99 ▶ return is_plain_coderef($token) ? $token->() : $token;
Branch: 1 branch
BranchTrueFalseTotal
is_plain_coderef($token) ? : 0 99 99
95 }
96  
97 3 ▶ return $self->token if $self->token && time() < $self->token_expires - 30;
Branch: 1 branch
BranchTrueFalseTotal
if $self->token and time < $self->token_expires - 30 2 1 3
Condition66%2/3
$self->token and time < $self->token_expires - 30
!ll&&!rl&&r
102
MC/DC50%1/2
$self->token and time < $self->token_expires - 30
$self->token time < $self->token_expires - 30
Truth table66%2/3
A and B
A= $self->tokenB= time < $self->token_expires - 30
ABresult
0X0
100
111
98  
99 1 my $sa = $self->service_account;
100 1 my $now = time();
101 my $jwt = encode_jwt(
102 payload => {
103 iss => $sa->{client_email},
104 scope => SCOPE,
105 aud => $sa->{token_uri} // TOKEN_URI,
106 iat => $now,
107 exp => $now + 3600,
108 },
109 key => \$sa->{private_key},
110 1 ▶ alg => 'RS256',
Condition50%1/2
$sa->{"token_uri"} // "https://oauth2.googleapis.com/token"
l!l
01
MC/DC0%0/1
$sa->{"token_uri"} // "https://oauth2.googleapis.com/token"
$sa->{"token_uri"}
Truth table50%1/2
A
A= $sa->{"token_uri"}
Aresult
11
00
111 );
112  
113 1 my $body = join '&',
114 'grant_type=' . uri_escape('urn:ietf:params:oauth:grant-type:jwt-bearer'),
115 'assertion=' . uri_escape($jwt);
116  
117 1 ▶ my $res = $self->ua->request( 'POST', $sa->{token_uri} // TOKEN_URI, {
Condition50%1/2
$sa->{"token_uri"} // "https://oauth2.googleapis.com/token"
l!l
01
MC/DC0%0/1
$sa->{"token_uri"} // "https://oauth2.googleapis.com/token"
$sa->{"token_uri"}
Truth table50%1/2
A
A= $sa->{"token_uri"}
Aresult
11
00
118 headers => { 'content-type' => 'application/x-www-form-urlencoded' },
119 content => $body,
120 });
121 1 $self->_croak_on_error($res);
122  
123 1 my $data = decode_json($res->{content});
124 1 $self->token($data->{access_token});
125 1 ▶ $self->token_expires($now + ($data->{expires_in} // 3600));
Condition50%1/2
$data->{"expires_in"} // 3600
l!l
10
MC/DC0%0/1
$data->{"expires_in"} // 3600
$data->{"expires_in"}
Truth table50%1/2
A
A= $data->{"expires_in"}
Aresult
11
00
126  
127 1 return $self->token;
128 }
129  
130 103 ▶ sub _croak_on_error ($self, $res) {
Subroutine _croak_on_error: called CC=6 SCAR=19.4
131 103 ▶ return if $res->{success};
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"success"} 98 5 103
132  
133 5 ▶ my $message = $res->{reason} // 'unknown error';
Condition50%1/2
$res->{"reason"} // "unknown error"
l!l
50
MC/DC0%0/1
$res->{"reason"} // "unknown error"
$res->{"reason"}
Truth table50%1/2
A
A= $res->{"reason"}
Aresult
11
00
134 5 ▶ if($res->{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->{"content"}) 5 0 5
135 5 my $data;
136 5 try {
137 5 $data = decode_json $res->{content};
138 5 ▶ $message = $data->{error}{message} if is_plain_hashref($data) && $data->{error}{message};
Branch: 1 branch
BranchTrueFalseTotal
if is_plain_hashref($data) and $data->{"error"}{"message"} 5 0 5
Condition33%1/3
is_plain_hashref($data) and $data->{"error"}{"message"}
!ll&&!rl&&r
005
MC/DC0%0/2
is_plain_hashref($data) and $data->{"error"}{"message"}
is_plain_hashref($data) $data->{"error"}{"message"}
Truth table33%1/3
A and B
A= is_plain_hashref($data)B= $data->{"error"}{"message"}
ABresult
0X0
100
111
139 } catch ($e) {
140 0 warn "warning decoding JSON: $e";
141 }
142 }
143 5 croak "Google Sheets API error ($res->{status}): $message";
144 }
145  
146 102 ▶ sub _request ($self, $method, $url, %opts) {
Subroutine _request: called CC=9 SCAR=22.0
147 102 ▶ my %headers = ( authorization => 'Bearer ' . $self->_access_token, ( $opts{headers} // {} )->%* );
Condition50%1/2
$opts{"headers"} // {}
l!l
0102
MC/DC0%0/1
$opts{"headers"} // {}
$opts{"headers"}
Truth table50%1/2
A
A= $opts{"headers"}
Aresult
11
00
148 102 my %http_opts = ( headers => \%headers );
149 102 ▶ if(defined $opts{body}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"body"}) 26 76 102
150 26 $headers{'content-type'} = 'application/json';
151 26 $http_opts{content} = encode_json($opts{body});
152 }
153  
154 102 ▶ my $attempts = ($self->backoff_retry // 0) + 1;
Condition100%2/2
$self->backoff_retry // 0
l!l
498
MC/DC100%1/1
$self->backoff_retry // 0
$self->backoff_retry
Truth table100%2/2
A
A= $self->backoff_retry
Aresult
11
00
155 102 my $res;
156 102 for my $attempt (1 .. $attempts) {
157 106 $res = $self->ua->request($method, $url, \%http_opts);
158 106 ▶ last if $res->{success} || $res->{status} != 429 || $attempt == $attempts;
Branch: 1 branch
BranchTrueFalseTotal
if $res->{"success"} or $res->{"status"} != 429 or $attempt == $attempts 102 4 106
Condition100%6/6
$res->{"success"} or $res->{"status"} != 429 or $attempt == $attempts
l!l&&r!l&&!r
10024
$res->{"success"} or $res->{"status"} != 429
l!l&&r!l&&!r
9736
MC/DC100%3/3
$res->{"success"} or $res->{"status"} != 429 or $attempt == $attempts
$res->{"success"} $res->{"status"} != 429 $attempt == $attempts
Truth table100%4/4
A or B or C
A= $res->{"success"}B= $res->{"status"} != 429C= $attempt == $attempts
ABCresult
1XX1
01X1
0011
0000
159 4 $SLEEP->(2 ** ($attempt - 1));
160 }
161 102 $self->_croak_on_error($res);
162  
163 97 ▶ return undef unless length $res->{content};
Branch: 1 branch
BranchTrueFalseTotal
unless length $res->{"content"} 0 97 97
164 97 return decode_json($res->{content});
165 }
166  
167 102 ▶ sub _url ($self, $segments = [], $action = undef, %query) {
Subroutine _url: called CC=5 SCAR=16.1
168 102 my $uri = URI->new(API_BASE);
169 102 $uri->path_segments($uri->path_segments, $self->spreadsheet_id, $segments->@*);
170 102 ▶ $uri->path($uri->path . $action) if defined $action;
Branch: 1 branch
BranchTrueFalseTotal
if defined $action 13 89 102
171 102 ▶ $uri->query_form(%query) if %query;
Branch: 1 branch
BranchTrueFalseTotal
if %query 66 36 102
172 102 return $uri;
173 }
174  
175 56 ▶ sub _quote_range ($self, $title, $a1 = undef) {
Subroutine _quote_range: called CC=3 SCAR=11.0
176 56 (my $quoted = $title) =~ s/'/''/g;
177 56 my $range = "'$quoted'";
178 56 ▶ $range .= "!$a1" if defined $a1;
Branch: 1 branch
BranchTrueFalseTotal
if defined $a1 49 7 56
179 56 return $range;
180 }
181  
182 38 ▶ sub sheet_titles ($self) {
Subroutine sheet_titles: called CC=2 SCAR=7.0
Pod documented
183 38 $self->flush;
184 38 my $data = $self->_request('GET', $self->_url([], undef, fields => 'sheets.properties.title'));
185 33 ▶ return [ map { $_->{properties}{title} } ( $data->{sheets} // [] )->@* ];
Condition50%1/2
$data->{"sheets"} // []
l!l
330
MC/DC0%0/1
$data->{"sheets"} // []
$data->{"sheets"}
Truth table50%1/2
A
A= $data->{"sheets"}
Aresult
11
00
186 }
187  
188 4 ▶ sub sheet_id_for_title ($self, $title) {
Subroutine sheet_id_for_title: called CC=4 SCAR=13.9
Pod documented
189 4 $self->flush;
190 4 my $data = $self->_request('GET', $self->_url([], undef, fields => 'sheets.properties'));
191 4 ▶ for my $sheet (( $data->{sheets} // [] )->@*) {
Condition50%1/2
$data->{"sheets"} // []
l!l
40
MC/DC0%0/1
$data->{"sheets"} // []
$data->{"sheets"}
Truth table50%1/2
A
A= $data->{"sheets"}
Aresult
11
00
192 6 ▶ return $sheet->{properties}{sheetId} if $sheet->{properties}{title} eq $title;
Branch: 1 branch
BranchTrueFalseTotal
if $sheet->{"properties"}{"title"} eq $title 2 4 6
193 }
194 2 return undef;
195 }
196  
197 20 ▶ sub get_value ($self, $title, $a1) {
Subroutine get_value: called CC=3 SCAR=11.0
Pod documented
198 20 $self->flush;
199 20 my $data = $self->_request('GET', $self->_url([ 'values', $self->_quote_range($title, $a1) ]));
200 20 ▶ my $row = ($data->{values} // [])->[0] // [];
Condition100%4/4
+($data->{"values"} // [])->[0] // []
l!l
164
$data->{"values"} // []
l!l
164
MC/DC100%1/1
+($data->{"values"} // [])->[0] // []
$data->{"values"}
Truth table100%2/2
A
A= $data->{"values"}
Aresult
11
00
201 20 return $row->[0];
202 }
203  
204 8 ▶ sub get_formula ($self, $title, $a1) {
Subroutine get_formula: called CC=3 SCAR=11.4
Pod documented
205 8 $self->flush;
206 8 my $data = $self->_request('GET',
207 $self->_url([ 'values', $self->_quote_range($title, $a1) ], undef, valueRenderOption => 'FORMULA'));
208 8 ▶ my $row = ($data->{values} // [])->[0] // [];
Condition50%2/4
+($data->{"values"} // [])->[0] // []
l!l
80
$data->{"values"} // []
l!l
80
MC/DC0%0/1
+($data->{"values"} // [])->[0] // []
$data->{"values"}
Truth table50%1/2
A
A= $data->{"values"}
Aresult
11
00
209 8 return $row->[0];
210 }
211  
212 19 ▶ sub update_value ($self, $title, $a1, $value) {
Subroutine update_value: called CC=3 SCAR=11.0
Pod documented
213 19 my $range = $self->_quote_range($title, $a1);
214  
215 19 ▶ if($self->batch_size) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->batch_size) { } 6 13 19
216 6 push $self->_pending->@*, { range => $range, majorDimension => 'ROWS', values => [[$value]] };
217 6 ▶ $self->flush if $self->_pending->@* >= $self->batch_size;
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->_pending} >= $self->batch_size 1 5 6
218 }
219 else {
220 13 $self->_request('PUT', $self->_url([ 'values', $range ], undef, valueInputOption => 'USER_ENTERED'),
221 body => { range => $range, majorDimension => 'ROWS', values => [[$value]] },
222 );
223 }
224  
225 19 return;
226 }
227  
228 90 ▶ sub flush ($self) {
Subroutine flush: called CC=2 SCAR=6.9
Pod documented
229 90 ▶ return unless $self->_pending->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->_pending} 85 5 90
230  
231 5 my $data = $self->_pending;
232 5 $self->_pending([]);
233  
234 5 $self->_request('POST', $self->_url([ 'values' ], ':batchUpdate'), body => {
235 valueInputOption => 'USER_ENTERED',
236 data => $data,
237 });
238  
239 5 return;
240 }
241  
242 2 ▶ sub clear_value ($self, $title, $a1) {
Subroutine clear_value: called CC=1 SCAR=0.0
Pod documented
243 2 $self->clear_range($title, $a1);
244 2 return;
245 }
246  
247 3 ▶ sub clear_range ($self, $title, $a1 = undef) {
Subroutine clear_range: called CC=2 SCAR=6.9
Pod documented
248 3 $self->flush;
249 3 $self->_request('POST', $self->_url([ 'values', $self->_quote_range($title, $a1) ], ':clear'), body => {});
250 3 return;
251 }
252  
253 3 ▶ sub get_all_values ($self, $title) {
Subroutine get_all_values: called CC=2 SCAR=6.9
Pod documented
254 3 $self->flush;
255 3 my $data = $self->_request('GET', $self->_url([ 'values', $self->_quote_range($title) ]));
256 3 ▶ return $data->{values} // [];
Condition100%2/2
$data->{"values"} // []
l!l
21
MC/DC100%1/1
$data->{"values"} // []
$data->{"values"}
Truth table100%2/2
A
A= $data->{"values"}
Aresult
11
00
257 }
258  
259 3 ▶ sub get_all_formulas ($self, $title) {
Subroutine get_all_formulas: called CC=2 SCAR=7.1
Pod documented
260 3 $self->flush;
261 3 my $data = $self->_request('GET',
262 $self->_url([ 'values', $self->_quote_range($title) ], undef, valueRenderOption => 'FORMULA'));
263 3 ▶ return $data->{values} // [];
Condition50%1/2
$data->{"values"} // []
l!l
30
MC/DC0%0/1
$data->{"values"} // []
$data->{"values"}
Truth table50%1/2
A
A= $data->{"values"}
Aresult
11
00
264 }
265  
266 3 ▶ sub add_sheet ($self, $title) {
Subroutine add_sheet: called CC=1 SCAR=0.0
Pod documented
267 3 $self->flush;
268 3 $self->_request('POST', $self->_url([], ':batchUpdate'), body => {
269 requests => [ { addSheet => { properties => { title => $title } } } ],
270 });
271 3 return;
272 }
273  
274 2 ▶ sub delete_sheet ($self, $title) {
Subroutine delete_sheet: called CC=2 SCAR=6.9
Pod documented
275 2 $self->flush;
276 2 my $sheet_id = $self->sheet_id_for_title($title);
277 2 ▶ croak "no such worksheet: $title" unless defined $sheet_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sheet_id 1 1 2
278 1 $self->_request('POST', $self->_url([], ':batchUpdate'), body => {
279 requests => [ { deleteSheet => { sheetId => $sheet_id } } ],
280 });
281 1 return;
282 }
283  
284 2 ▶ sub copy_worksheet ($self, $from_title, $to_title) {
Subroutine copy_worksheet: called CC=2 SCAR=6.9
Pod documented
285 2 $self->flush;
286 2 my $sheet_id = $self->sheet_id_for_title($from_title);
287 2 ▶ croak "no such worksheet: $from_title" unless defined $sheet_id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sheet_id 1 1 2
288 1 $self->_request('POST', $self->_url([], ':batchUpdate'), body => {
289 requests => [ { duplicateSheet => {
290 sourceSheetId => $sheet_id,
291 newSheetName => $to_title,
292 } } ],
293 });
294 1 return;
295 }
296  
297 18 ▶ sub DEMOLISH ($self, $global_destruction) {
Subroutine DEMOLISH: called CC=4 SCAR=14.3
Pod undocumented
298 18 ▶ return if $global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if $global_destruction 0 18 18
299 18 ▶ return unless $self->{_pending} && $self->{_pending}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_pending"} and @{$self->{"_pending"}} 17 1 18
Condition66%2/3
$self->{"_pending"} and @{$self->{"_pending"}}
!ll&&!rl&&r
0171
MC/DC50%1/2
$self->{"_pending"} and @{$self->{"_pending"}}
$self->{"_pending"} @{$self->{"_pending"}}
Truth table66%2/3
A and B
A= $self->{"_pending"}B= @{$self->{"_pending"}}
ABresult
0X0
100
111
300 1 try {
301 1 $self->flush;
302 } catch ($e) {
303 0 warn "warning flushing DEMOLISH: $e";
304 }
305 1 return;
306 }
307  
308 }
309  
310 __END__
↑ Summary Sheets/Worksheet.pm »