Sheets/Worksheet.pm

filter: Statementstmt 100% 55 / 55 Branchbran 100% 16 / 16 Conditioncond 69.2% 9 / 13 MC/DCmcdc 42.8% 3 / 7 Subroutinesub 100% 16 / 16 Podpod 50.0% 1 / 2 totaltotal 91.7% 100 / 109 CC 17 SCAR 12.6
CC
17
Cov
95%
FIRSTKEY
7.0
fetch_mode
5.0
NEXTKEY
4.0
CRAP 3.5
« Sheets/Client.pm ↑ Summary Sheets.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::Worksheet 0.02 {
5  
6 # ABSTRACT: Tie a hash to the cells of a single Google Sheets worksheet
7  
8 3 ▶ use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 our @CARP_NOT = qw( Tie::Google::Sheets Tie::Google::Sheets::Client Class::Tiny::Object );
11  
12 3 ▶ use Class::Tiny qw( _client _title ), {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 _fetch_mode => 'value',
14 3 };
15  
16 15 ▶ sub BUILDARGS ($class, %args) {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod undocumented
17 return {
18 _client => $args{client},
19 _title => $args{title},
20 15 };
21 }
22  
23 15 ▶ sub TIEHASH ($class, %args) {
Subroutine TIEHASH: called CC=1 SCAR=0.0
24 15 return $class->new(%args);
25 }
26  
27 5 ▶ sub fetch_mode ($self, @args) {
Subroutine fetch_mode: called CC=5 SCAR=16.1
Pod documented
28 5 ▶ if(@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 3 2 5
29 3 my $mode = $args[0];
30 3 ▶ croak "fetch_mode must be 'value' or 'formula'"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mode and $mode eq "value" || $mode eq "formula" 1 2 3
Condition83%5/6
defined $mode and $mode eq "value" || $mode eq "formula"
!ll&&!rl&&r
012
$mode eq "value" or $mode eq "formula"
l!l&&r!l&&!r
111
MC/DC66%2/3
defined $mode and $mode eq "value" || $mode eq "formula"
defined $mode $mode eq "value" $mode eq "formula"
Truth table75%3/4
A and B or C
A= defined $modeB= $mode eq "value"C= $mode eq "formula"
ABCresult
0XX0
1000
11X1
1011
31 unless defined $mode && ($mode eq 'value' || $mode eq 'formula');
32 2 $self->_fetch_mode($mode);
33 }
34 4 return $self->_fetch_mode;
35 }
36  
37 49 ▶ sub _normalize_key ($self, $key) {
Subroutine _normalize_key: called CC=2 SCAR=6.9
38 49 ▶ croak "invalid cell reference: $key" unless $key =~ /^[A-Za-z]+[1-9][0-9]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $key =~ /^[A-Za-z]+[1-9][0-9]*\z/u 3 46 49
39 46 return uc $key;
40 }
41  
42 27 ▶ sub FETCH ($self, $key) {
Subroutine FETCH: called CC=2 SCAR=6.9
43 27 ▶ my $method = $self->_fetch_mode eq 'formula' ? 'get_formula' : 'get_value';
Branch: 1 branch
BranchTrueFalseTotal
$self->_fetch_mode eq 'formula' ? : 6 21 27
44 27 return $self->_client->$method($self->_title, $self->_normalize_key($key));
45 }
46  
47 20 ▶ sub STORE ($self, $key, $value) {
Subroutine STORE: called CC=1 SCAR=0.0
48 20 $self->_client->update_value($self->_title, $self->_normalize_key($key), $value);
49 19 return $value;
50 }
51  
52 2 ▶ sub DELETE ($self, $key) {
Subroutine DELETE: called CC=1 SCAR=0.0
53 2 $key = $self->_normalize_key($key);
54 2 my $old = $self->FETCH($key);
55 2 $self->_client->clear_value($self->_title, $key);
56 2 return $old;
57 }
58  
59 2 ▶ sub EXISTS ($self, $key) {
Subroutine EXISTS: called CC=1 SCAR=0.0
60 2 return defined $self->FETCH($key);
61 }
62  
63 1 ▶ sub CLEAR ($self) {
Subroutine CLEAR: called CC=1 SCAR=0.0
64 1 $self->_client->clear_range($self->_title);
65 1 return;
66 }
67  
68 4 ▶ sub FIRSTKEY ($self) {
Subroutine FIRSTKEY: called CC=7 SCAR=19.5
69 4 ▶ my $method = $self->_fetch_mode eq 'formula' ? 'get_all_formulas' : 'get_all_values';
Branch: 1 branch
BranchTrueFalseTotal
$self->_fetch_mode eq 'formula' ? : 2 2 4
70 4 my $grid = $self->_client->$method($self->_title);
71 4 my @keys;
72 4 for my $r (0 .. $grid->$#*) {
73 4 ▶ my $row = $grid->[$r] // [];
Condition50%1/2
$grid->[$r] // []
l!l
40
MC/DC0%0/1
$grid->[$r] // []
$grid->[$r]
Truth table50%1/2
A
A= $grid->[$r]
Aresult
11
00
74 4 for my $c (0 .. $row->$#*) {
75 10 my $val = $row->[$c];
76 10 ▶ next unless defined $val && length $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and length $val 2 8 10
Condition66%2/3
defined $val and length $val
!ll&&!rl&&r
028
MC/DC50%1/2
defined $val and length $val
defined $val length $val
Truth table66%2/3
A and B
A= defined $valB= length $val
ABresult
0X0
100
111
77 8 push @keys, _col_letter($c + 1) . ($r + 1);
78 }
79 }
80 4 $self->{_iter} = \@keys;
81 4 $self->{_iter_pos} = 0;
82 4 return $self->NEXTKEY;
83 }
84  
85 12 ▶ sub NEXTKEY ($self, $lastkey = undef) {
Subroutine NEXTKEY: called CC=4 SCAR=13.9
86 12 ▶ my $keys = $self->{_iter} // [];
Condition50%1/2
$self->{"_iter"} // []
l!l
120
MC/DC0%0/1
$self->{"_iter"} // []
$self->{"_iter"}
Truth table50%1/2
A
A= $self->{"_iter"}
Aresult
11
00
87 12 ▶ return undef if $self->{_iter_pos} >= @$keys;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_iter_pos"} >= @$keys 4 8 12
88 8 return $keys->[ $self->{_iter_pos}++ ];
89 }
90  
91 8 ▶ sub _col_letter ($n) {
Subroutine _col_letter: called CC=2 SCAR=6.9
92 8 my $s = '';
93 8 ▶ while($n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0) 8 8 16
94 8 my $rem = ($n - 1) % 26;
95 8 $s = chr(65 + $rem) . $s;
96 8 $n = int(($n - 1) / 26);
97 }
98 8 return $s;
99 }
100  
101 }
102  
103 __END__
« Sheets/Client.pm ↑ Summary Sheets.pm »