| 1 | package Google::RestApi::SheetsApi4::RangeGroup; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # some private subroutines of Range are called from here, | ||||||||||||||||||||||||||||
| 4 | # so think of RangeGroup as a friend of Range. the routines | ||||||||||||||||||||||||||||
| 5 | # called are commented thusly: | ||||||||||||||||||||||||||||
| 6 | # "private range routine called here!" | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '2.2.5'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Google::RestApi::Setup; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use List::Util qw( first ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Storable qw( dclone ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use aliased 'Google::RestApi::SheetsApi4::RangeGroup::Iterator'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 26 | my $class = shift; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 26 | state $check = signature( | |||||||||||||||||||||||||||
| 22 | bless => !!0, | ||||||||||||||||||||||||||||
| 23 | named => [ | ||||||||||||||||||||||||||||
| 24 | spreadsheet => HasApi, | ||||||||||||||||||||||||||||
| 25 | ranges => ArrayRef[HasRange], { default => [] }, | ||||||||||||||||||||||||||||
| 26 | ], | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 26 | return bless $check->(@_), $class; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub push_ranges { | ||||||||||||||||||||||||||
|
Subroutine
push_ranges: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 0 | state $check = signature(positional => [slurpy ArrayRef[HasRange]]); | |||||||||||||||||||||||||||
| 35 | 0 | my ($ranges) = $check->(@_); | |||||||||||||||||||||||||||
| 36 | 0 | push(@{ $self->{ranges} }, @$ranges); | |||||||||||||||||||||||||||
| 37 | 0 | return; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub clear { | ||||||||||||||||||||||||||
|
Subroutine
clear: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | $self->clear_cached_values(); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my @ranges = map { $_->range(); } $self->ranges(); | |||||||||||||||||||||||||||
| 46 | 0 | my %p = ( | |||||||||||||||||||||||||||
| 47 | content => { ranges => \@ranges }, | ||||||||||||||||||||||||||||
| 48 | uri => "/values:batchClear", | ||||||||||||||||||||||||||||
| 49 | method => "post", | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | 0 | return $self->api(%p); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub clear_cached_values { | ||||||||||||||||||||||||||
|
Subroutine
clear_cached_values: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 0 | $_->clear_cached_values() foreach $self->ranges(); | |||||||||||||||||||||||||||
| 57 | 0 | return; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub refresh_values { | ||||||||||||||||||||||||||
|
Subroutine
refresh_values: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 0 | $self->clear_cached_values(); | |||||||||||||||||||||||||||
| 63 | 0 | return $self->values(); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 19 | ▶ | sub values { | ||||||||||||||||||||||||||
|
Subroutine
values: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 19 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 19 | state $check = signature( | |||||||||||||||||||||||||||
| 70 | bless => !!0, | ||||||||||||||||||||||||||||
| 71 | named => [ | ||||||||||||||||||||||||||||
| 72 | params => HashRef, { default => {} }, | ||||||||||||||||||||||||||||
| 73 | _extra_ => slurpy HashRef, | ||||||||||||||||||||||||||||
| 74 | ], | ||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||
| 76 | 19 | my $p = named_extra($check->(@_)); | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 19 | my @ranges = $self->ranges(); | |||||||||||||||||||||||||||
| 79 | 19 | my @needs_values = grep { !$_->has_values(); } @ranges; | |||||||||||||||||||||||||||
| 80 | # for some reason google designed this so that you can set | ||||||||||||||||||||||||||||
| 81 | # various ranges in the params, but only one majorDimension | ||||||||||||||||||||||||||||
| 82 | # for the entire url. it's a bit strange since the return | ||||||||||||||||||||||||||||
| 83 | # values have a majorDimension in each range. all other parts | ||||||||||||||||||||||||||||
| 84 | # of their api treat range/majorDimension as a unit except for | ||||||||||||||||||||||||||||
| 85 | # batchGet. so we have to potentially do two calls for a | ||||||||||||||||||||||||||||
| 86 | # batch get, one for cols, and one for rows. | ||||||||||||||||||||||||||||
| 87 | 19 | my (@cols, @rows); | |||||||||||||||||||||||||||
| 88 | 19 | foreach (@needs_values) { | |||||||||||||||||||||||||||
| 89 | 23 | ▶ | if ($_->dimension() =~ /^col/i) { push(@cols, $_); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 20 | else { push(@rows, $_); } | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 19 | $self->_batch_get('col', dclone($p), \@cols); | |||||||||||||||||||||||||||
| 93 | 19 | $self->_batch_get('row', dclone($p), \@rows); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 19 | my @values = map { $_->values(); } @ranges; | |||||||||||||||||||||||||||
| 96 | 19 | return \@values; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 38 | ▶ | sub _batch_get { | ||||||||||||||||||||||||||
|
Subroutine
_batch_get: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 100 | 38 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 38 | my ($dim, $p, $ranges) = @_; | |||||||||||||||||||||||||||
| 103 | 38 | ▶ | return if !$ranges || !@$ranges; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ranges and @$ranges
MC/DC50%1/2
$ranges and @$ranges
$ranges
@$ranges
Truth table66%2/3
A and B
A= $rangesB= @$ranges
| |||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 9 | my @ranges = map { $_->range(); } @$ranges; | |||||||||||||||||||||||||||
| 106 | 9 | $p->{params}->{ranges} = \@ranges; | |||||||||||||||||||||||||||
| 107 | 9 | ▶ | $p->{params}->{majorDimension} = 'COLUMNS' if $dim =~ /^col/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 9 | $p->{uri} = "/values:batchGet"; | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 9 | my $response = $self->api(%$p); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 9 | my $value_ranges = $response->{valueRanges}; | |||||||||||||||||||||||||||
| 113 | # private range routine called here! | ||||||||||||||||||||||||||||
| 114 | 9 | my @ranges2 = map { $_->range(); } @$ranges; | |||||||||||||||||||||||||||
| 115 | 23 | $ranges->[$_]->_cache_range_values(%{ $value_ranges->[$_] }) | |||||||||||||||||||||||||||
| 116 | 9 | foreach (0..$#$ranges); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 9 | return; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 10 | ▶ | sub batch_values { | ||||||||||||||||||||||||||
|
Subroutine
batch_values: called CC=5 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 10 | state $check = signature( | |||||||||||||||||||||||||||
| 125 | bless => !!0, | ||||||||||||||||||||||||||||
| 126 | named => [ | ||||||||||||||||||||||||||||
| 127 | values => ArrayRef, { optional => 1 }, | ||||||||||||||||||||||||||||
| 128 | ], | ||||||||||||||||||||||||||||
| 129 | ); | ||||||||||||||||||||||||||||
| 130 | 10 | my $p = $check->(@_); | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 10 | my $values = $p->{values}; | |||||||||||||||||||||||||||
| 133 | 10 | ▶ | if (defined $values) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | my @ranges = $self->ranges(); | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | LOGDIE "Too many values provided for range group" if scalar @$values > scalar @ranges; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | $ranges[$_]->batch_values(values => $values->[$_]) foreach (0..$#$values); | |||||||||||||||||||||||||||
| 137 | 0 | return $self; | |||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | my @batch_values = map { | ||||||||||||||||||||||||||||
| 141 | 10 | ▶ | $_->has_values() ? ($_->batch_values()) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | } $self->ranges(); | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 10 | return \@batch_values; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 10 | ▶ | sub values_response_from_api { | ||||||||||||||||||||||||||
|
Subroutine
values_response_from_api: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 148 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 149 | 10 | state $check = signature(positional => [ArrayRef]); | |||||||||||||||||||||||||||
| 150 | 10 | my ($updates) = $check->(@_); | |||||||||||||||||||||||||||
| 151 | my @updates = map { | ||||||||||||||||||||||||||||
| 152 | 10 | ▶ | $_->has_values() ? ($_->values_response_from_api($updates)) : (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | } $self->ranges(); | ||||||||||||||||||||||||||||
| 154 | 10 | return \@updates; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 10 | ▶ | sub submit_values { | ||||||||||||||||||||||||||
|
Subroutine
submit_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 159 | 10 | $self->spreadsheet()->submit_values(ranges => [ $self ], @_); | |||||||||||||||||||||||||||
| 160 | 10 | return $self->values(); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | ▶ | sub batch_requests { | ||||||||||||||||||||||||||
|
Subroutine
batch_requests: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 164 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 165 | my @batch_requests = map { | ||||||||||||||||||||||||||||
| 166 | 2 | $_->batch_requests(@_); | |||||||||||||||||||||||||||
| 167 | } $self->ranges(); | ||||||||||||||||||||||||||||
| 168 | 2 | return @batch_requests; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 1 | ▶ | sub submit_requests { | ||||||||||||||||||||||||||
|
Subroutine
submit_requests: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 173 | 1 | return $self->spreadsheet()->submit_requests(ranges => [ $self ], @_); | |||||||||||||||||||||||||||
| 174 | # return $self; | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 1 | ▶ | sub requests_response_from_api { | ||||||||||||||||||||||||||
|
Subroutine
requests_response_from_api: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 179 | 1 | state $check = signature(positional => [ArrayRef]); | |||||||||||||||||||||||||||
| 180 | 1 | my ($requests) = $check->(@_); | |||||||||||||||||||||||||||
| 181 | my @requests = map { | ||||||||||||||||||||||||||||
| 182 | 1 | $_->requests_response_from_api($requests); | |||||||||||||||||||||||||||
| 183 | } $self->ranges(); | ||||||||||||||||||||||||||||
| 184 | 1 | return \@requests; | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 1 | ▶ | sub iterator { | ||||||||||||||||||||||||||
|
Subroutine
iterator: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 188 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 189 | 1 | return Iterator->new(@_, range_group => $self); | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 10 | ▶ | sub has_values { | ||||||||||||||||||||||||||
|
Subroutine
has_values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 193 | 10 | my $self = shift; | |||||||||||||||||||||||||||
| 194 | 10 | ▶ | return first { $_->has_values(); } $self->ranges(); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | # enables pass-throughs to the underlying ranges so you can go: | ||||||||||||||||||||||||||||
| 198 | # $range_group->red()->bold() etc. | ||||||||||||||||||||||||||||
| 199 | 28 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 200 | 28 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 201 | 28 | ▶ | return if $AUTOLOAD =~ /DESTROY$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 2 | ▶ | return if $AUTOLOAD =~ /\0$/; # wtf is this??? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 205 | 2 | my $method = (split('::', $AUTOLOAD))[-1]; | |||||||||||||||||||||||||||
| 206 | 2 | $_->$method(@_) for $self->ranges(); | |||||||||||||||||||||||||||
| 207 | 2 | return $self; | |||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 64 | ▶ | sub ranges { @{ shift->{ranges} }; } | ||||||||||||||||||||||||||
|
Subroutine
ranges: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 211 | 26 | ▶ | sub spreadsheet { shift->{spreadsheet}; } | ||||||||||||||||||||||||||
|
Subroutine
spreadsheet: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 9 | ▶ | sub api { shift->spreadsheet()->api(@_); } | ||||||||||||||||||||||||||
|
Subroutine
api: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub sheets_api { shift->spreadsheet()->sheets_api(); } | ||||||||||||||||||||||||||
|
Subroutine
sheets_api: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | sub rest_api { shift->sheets_api()->rest_api(); } | ||||||||||||||||||||||||||
|
Subroutine
rest_api: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub transaction { shift->rest_api()->transaction(); } | ||||||||||||||||||||||||||
|
Subroutine
transaction: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 2 | 1; | |||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | __END__ | ||||||||||||||||||||||||||||