line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Google::RestApi::SheetsApi4::RangeGroup::Tie; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '1.0.3'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
611
|
use Google::RestApi::Setup; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
13368
|
use Tie::Hash (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
8
|
1
|
|
|
1
|
|
5
|
use aliased 'Google::RestApi::SheetsApi4::RangeGroup::Tie::Iterator'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
125
|
use parent -norequire, 'Tie::StdHash'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub iterator { |
12
|
1
|
|
|
1
|
1
|
9
|
my $self = shift; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
|
|
5
|
my $tied = $self->spreadsheet()->tie(%{ $self->ranges() }); |
|
1
|
|
|
|
|
6
|
|
15
|
1
|
50
|
|
|
|
4
|
tied(%$tied)->default_worksheet($self->worksheet()) |
16
|
|
|
|
|
|
|
if $self->worksheet(); |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
|
|
13
|
return Iterator->new(@_, tied => $tied); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub values { |
22
|
3
|
|
|
3
|
1
|
19
|
my $self = shift; |
23
|
3
|
|
|
|
|
16
|
my $range_group = $self->range_group(); |
24
|
3
|
|
|
|
|
145
|
return $range_group->values(@_); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub batch_values { |
28
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
29
|
0
|
|
|
|
|
0
|
my $range_group = $self->range_group(); |
30
|
0
|
|
|
|
|
0
|
return $range_group->batch_values(@_); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub add_ranges { |
34
|
21
|
|
|
21
|
1
|
43
|
my $self = shift; |
35
|
21
|
|
|
|
|
76
|
my %ranges = @_; |
36
|
21
|
|
|
|
|
45
|
state $check = compile(slurpy ArrayRef[HasRange]); |
37
|
21
|
|
|
|
|
6789
|
$check->(CORE::values %ranges); |
38
|
21
|
|
|
|
|
438
|
@{ $self->{ranges} }{ keys %ranges } = CORE::values %ranges; |
|
21
|
|
|
|
|
87
|
|
39
|
21
|
|
|
|
|
59
|
return \%ranges; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub add_tied { |
43
|
5
|
|
|
5
|
1
|
18
|
my $self = shift; |
44
|
5
|
|
|
|
|
12
|
state $check = compile(HashRef); |
45
|
5
|
|
|
|
|
2264
|
my ($tied) = $check->(@_); |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
59
|
my $fetch_range = tied(%$tied)->fetch_range(); |
48
|
5
|
|
|
|
|
18
|
tied(%$tied)->fetch_range(1); |
49
|
5
|
|
|
|
|
23
|
$self->add_ranges(%$tied); |
50
|
5
|
|
|
|
|
25
|
tied(%$tied)->fetch_range($fetch_range); |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
20
|
return $tied; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# fetch_range(1) turns it on, fetch_range(0) turns it off. |
56
|
|
|
|
|
|
|
# fetch_range() returns current setting. return $self so it can be |
57
|
|
|
|
|
|
|
# chained with requests. |
58
|
|
|
|
|
|
|
sub fetch_range { |
59
|
25
|
|
|
25
|
1
|
1456
|
my $self = shift; |
60
|
25
|
|
|
|
|
47
|
my $fetch_range = shift; |
61
|
25
|
100
|
|
|
|
71
|
return $self->{fetch_range} if !defined $fetch_range; |
62
|
|
|
|
|
|
|
|
63
|
15
|
100
|
|
|
|
50
|
if ($fetch_range) { |
64
|
10
|
|
|
|
|
22
|
$self->{fetch_range} = 1; |
65
|
|
|
|
|
|
|
} else { |
66
|
5
|
|
|
|
|
31
|
delete $self->{fetch_range}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
15
|
|
|
|
|
40
|
return $self; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub range_group { |
73
|
12
|
|
|
12
|
1
|
38
|
my $self = shift; |
74
|
12
|
|
|
|
|
60
|
return $self->spreadsheet()->range_group(CORE::values %{ $self->ranges() }); |
|
12
|
|
|
|
|
38
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub default_worksheet { |
78
|
18
|
|
|
18
|
1
|
38
|
my $self = shift; |
79
|
18
|
|
|
|
|
36
|
state $check = compile( |
80
|
|
|
|
|
|
|
HasMethods[qw(tie_ranges tie_cells)], { optional => 1 }, |
81
|
|
|
|
|
|
|
); |
82
|
18
|
|
|
|
|
2777
|
my ($worksheet) = $check->(@_); |
83
|
18
|
100
|
|
|
|
304
|
$self->{worksheet} = $worksheet if $worksheet; |
84
|
18
|
|
|
|
|
99
|
return $self->{worksheet}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub TIEHASH { |
88
|
16
|
|
|
16
|
|
45
|
my $class = shift; |
89
|
16
|
|
|
|
|
44
|
state $check = compile( |
90
|
|
|
|
|
|
|
HasMethods[qw(range_group)], |
91
|
|
|
|
|
|
|
); |
92
|
16
|
|
|
|
|
2830
|
my ($spreadsheet) = $check->(@_); |
93
|
16
|
|
|
|
|
287
|
my $self = bless {}, $class; |
94
|
16
|
|
|
|
|
65
|
$self->{spreadsheet} = $spreadsheet; |
95
|
16
|
|
|
|
|
63
|
return $self; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub FIRSTKEY { |
99
|
7
|
|
|
7
|
|
17
|
my $self = shift; |
100
|
7
|
|
|
|
|
13
|
my $a = keys %{ $self->ranges() }; # reset each() iterator |
|
7
|
|
|
|
|
27
|
|
101
|
7
|
|
|
|
|
17
|
return each %{ $self->ranges() }; |
|
7
|
|
|
|
|
20
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub NEXTKEY { |
105
|
13
|
|
|
13
|
|
26
|
return each %{ shift->ranges() }; |
|
13
|
|
|
|
|
61
|
|
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub FETCH { |
109
|
34
|
|
|
34
|
|
5510
|
my $self = shift; |
110
|
34
|
|
|
|
|
63
|
my $key = shift; |
111
|
34
|
50
|
|
|
|
87
|
my $range = $self->ranges()->{$key} |
112
|
|
|
|
|
|
|
or LOGDIE "No range found for key '$key'"; |
113
|
34
|
50
|
|
|
|
230
|
return $self->{fetch_range} ? $range : $range->values(); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub STORE { |
117
|
25
|
|
|
25
|
|
163
|
my $self = shift; |
118
|
|
|
|
|
|
|
|
119
|
25
|
|
|
|
|
70
|
my ($key, $value) = @_; |
120
|
25
|
100
|
|
|
|
67
|
if (!$self->ranges()->{$key}) { |
121
|
4
|
50
|
|
|
|
13
|
my $worksheet = $self->worksheet() |
122
|
|
|
|
|
|
|
or LOGDIE "No default worksheet provided for new range '$key'. Call default_worksheet() first."; |
123
|
4
|
|
|
|
|
19
|
my $tied = $worksheet->tie_ranges({ $key => $key }); |
124
|
4
|
|
|
|
|
16
|
$self->add_tied($tied); |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
25
|
50
|
|
|
|
89
|
if (ref($value) eq "HASH") { |
128
|
0
|
|
|
|
|
0
|
$self->ranges()->{$key}->batch_requests($value); |
129
|
|
|
|
|
|
|
} else { |
130
|
25
|
|
|
|
|
60
|
$self->ranges()->{$key}->batch_values(values => $value); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
25
|
|
|
|
|
134
|
return; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
0
|
0
|
0
|
sub clear_cached_values { shift->range_group()->clear_cached_values(@_); } |
137
|
0
|
|
|
0
|
1
|
0
|
sub refresh_values { shift->range_group()->refresh_values(@_); } |
138
|
8
|
|
|
8
|
1
|
85
|
sub submit_values { shift->range_group()->submit_values(@_); } |
139
|
1
|
|
|
1
|
1
|
5
|
sub submit_requests { shift->range_group()->submit_requests(@_); } |
140
|
0
|
|
|
0
|
0
|
0
|
sub transaction { shift->range_group()->transaction(); } |
141
|
125
|
|
|
125
|
1
|
507
|
sub ranges { shift->{ranges}; } |
142
|
6
|
|
|
6
|
1
|
25
|
sub worksheet { shift->{worksheet}; } |
143
|
14
|
|
|
14
|
1
|
44
|
sub spreadsheet { shift->{spreadsheet}; } |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head1 NAME |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Google::RestApi::SheetsApi4::RangeGroup::Tie - Makes Ranges addressible via a hash key. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 DESCRIPTION |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
A RangeGroup::Tie is a |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
See the description and synopsis at Google::RestApi::SheetsApi4. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head1 SUBROUTINES |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=over |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item iterator(%args); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Returns an iterator for this tied range group. Each call to 'iterate' |
166
|
|
|
|
|
|
|
(or 'next') will return a tied range group of individual cells |
167
|
|
|
|
|
|
|
representing the iteration at that point. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Any 'args' are passed through to RangeGroup::Iterator::new. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item values(%args); |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Gets the values for the underlying range group. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Any 'args' are passed through to RangeGroup::Iterator::values. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item batch_values { |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Gets or sets the queued batch values for the underlying range group. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Any 'args' are passed through to RangeGroup::Iterator::batch_values. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item add_ranges(<hash<Range>>); |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Adds the passed 'index => Range' pairs to this tied range group. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item add_tied(<hashref<Range>>); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Adds the passed tied range group to this tied range group. |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item fetch_range(<bool>); |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Sets the option to return the underlying ranges when fetching the |
194
|
|
|
|
|
|
|
value. This allows you to set things like formatting on the underlying |
195
|
|
|
|
|
|
|
ranges when fetching by index. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=item range_group(); |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Returns the parent RangeGroup object. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item default_worksheet(); |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Sets the default worksheet to be used when auto-creating a new |
204
|
|
|
|
|
|
|
index. Each index points to a range, and each range must have |
205
|
|
|
|
|
|
|
a worksheet with which it is associated. So if a new index is |
206
|
|
|
|
|
|
|
created, we need to know to which worksheet that index needs |
207
|
|
|
|
|
|
|
to point. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item refresh_values(); |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
Calls the parent RangeGroup's refresh_values routine. |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item submit_values(); |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
Calls the parent RangeGroup's submit_values routine. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item submit_requests(); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Calls the parent RangeGroup's submit_requests routine. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item ranges(); |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Calls the parent RangeGroup's ranges routine. |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=item worksheet(); |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
Returns the parent default Worksheet object. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item spreadsheet(); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
Returns the parent Spreadsheet object. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
=back |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=head1 AUTHORS |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=over |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Robin Murray mvsjes@cpan.org |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=back |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=head1 COPYRIGHT |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
Copyright (c) 2021, Robin Murray. All rights reserved. |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. |