RestApi/SheetsApi4/Range/Col.pm

filter: Statementstmt 86.9% 73 / 84 Branchbran 85.7% 24 / 28 Conditioncond 64.2% 9 / 14 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 63.6% 14 / 22 Podpod 33.3% 4 / 12 totaltotal 75.1% 127 / 169 CC 20 SCAR 12.5
CC
20
Cov
84%
is_other_inside
7.1
_col_i2a
5.0
cell_at_offset
4.2
CRAP 3.5
« RestApi/DocsApi1.pm ↑ Summary RestApi/SheetsApi4/Range/Row.pm »
1 package Google::RestApi::SheetsApi4::Range::Col;
2  
3 2 our $VERSION = '2.2.5';
4  
5 2 ▶use Google::RestApi::Setup;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Try::Tiny qw( try catch );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use aliased 'Google::RestApi::SheetsApi4::Range';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use aliased 'Google::RestApi::SheetsApi4::Range::Cell';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use parent Range;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 51 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
15 51 my $class = shift;
16 51 my %self = @_;
17  
18 51 $self{dim} = 'col';
19 51 $self{range} = _col_i2a($self{range});
20  
21 # this is fucked up, but want to support creating this object directly and also
22 # via the range::factory method, so have to handle both cases here. try to create
23 # the col directly first (which could also come via the factory method, which will
24 # have already translated the address into a col), and failing that, see if the
25 # range factory can create a col (which will resolve any named or header references).
26 # this has the potential of looping between this and factory method.
27  
28 # if factory has already been used, then this should resolve here.
29 51 my $err;
30 51 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
31 51 state $check = signature(positional => [RangeCol]);
32 51 ($self{range}) = $check->($self{range});
33 4 ▶ } catch {
Subroutine __ANON__: called CC=1 SCAR=0.0
34 4 $err = $_;
35 51 };
36 51 ▶ return $class->SUPER::new(%self) if !$err;
Branch: 1 branch
BranchTrueFalseTotal
unless $err 47 4 51
37  
38 # see if the range passed can be translated to what we want via the factory.
39 4 my $factory_range;
40 4 ▶ try {
Subroutine __ANON__: called CC=1 SCAR=0.0
41 4 $factory_range = Google::RestApi::SheetsApi4::Range::factory(%self);
42 4 ▶ } catch {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
43 4 ▶ return $factory_range if $factory_range && $factory_range->isa(__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
if $factory_range and $factory_range->isa(__PACKAGE__) 2 2 4
Condition66%2/3
$factory_range and $factory_range->isa(__PACKAGE__)
!ll&&!rl&&r
022
MC/DC50%1/2
$factory_range and $factory_range->isa(__PACKAGE__)
$factory_range $factory_range->isa(__PACKAGE__)
Truth table66%2/3
A and B
A= $factory_rangeB= $factory_range->isa(__PACKAGE__)
ABresult
0X0
100
111
44  
45 2 LOGDIE sprintf("Unable to translate '%s' into a worksheet column: $err", flatten_range($self{range}));
46 }
47  
48 51 ▶sub _col_i2a {
Subroutine _col_i2a: called CC=5 SCAR=16.1
49 51 my $col = shift;
50  
51 51 ▶ return $col if ref($col);
Branch: 1 branch
BranchTrueFalseTotal
if ref $col 17 34 51
52 34 ▶ return $col if $col =~ qr/\D/;
Branch: 1 branch
BranchTrueFalseTotal
if $col =~ qr/\D/ 29 5 34
53 5 ▶ $col > 0 or die "Column number should greater than zero, got $col";
Branch: 1 branch
BranchTrueFalseTotal
$col > 0 or die "Column number should greater than zero, got $col" 5 0 5
54  
55 5 my $result = "";
56 5 ▶ while ($col > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($col > 0) 12 5 17
57 # The logic requires decrementing first to handle the missing zero symbol in the A-Z system
58 12 my $remainder = ($col - 1) % 26;
59 # Get the ASCII character for the letter (A is 65)
60 12 $result = chr($remainder + ord('A')) . $result;
61 # Update the column number for the next iteration
62 12 $col = int(($col - 1) / 26);
63 }
64 5 return $result;
65 }
66  
67 18 ▶sub values {
Subroutine values: called CC=3 SCAR=11.0
Pod documented
68 18 my $self = shift;
69 18 state $check = signature(
70 bless => !!0,
71 named => [
72 values => ArrayRef[Str], { optional => 1 },
73 _extra_ => slurpy HashRef,
74 ],
75 );
76 18 my $p = named_extra($check->(@_));
77 18 ▶ $p->{values} = [ $p->{values} ] if defined $p->{values};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$p{"values"} 1 17 18
78 18 my $values = $self->SUPER::values(%$p);
79 18 ▶ return defined $values ? $values->[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $values ? : 15 3 18
80 }
81  
82 12 ▶sub batch_values {
Subroutine batch_values: called CC=2 SCAR=6.9
Pod documented
83 12 my $self = shift;
84 12 state $check = signature(
85 bless => !!0,
86 named => [
87 values => ArrayRef[Str], { optional => 1 },
88 ],
89 );
90 12 my $p = $check->(@_);
91 12 ▶ $p->{values} = [ $p->{values} ] if $p->{values};
Branch: 1 branch
BranchTrueFalseTotal
if $$p{"values"} 6 6 12
92 12 return $self->SUPER::batch_values(%$p);
93 }
94  
95 12 ▶sub cell_at_offset {
Subroutine cell_at_offset: called CC=4 SCAR=14.4
Pod undocumented
96 12 my $self = shift;
97  
98 12 state $check = signature(positional => [Int, DimColRow, { optional => 1 }]);
99 12 my ($offset) = $check->(@_); # we're a column, no dim required.
100  
101 12 my $col_range = $self->range_to_array($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED); # can't use aliased.
102 12 my $cell_range = $col_range->[0];
103 12 ▶ $cell_range->[1] = ($cell_range->[1] || 1) + $offset;
Condition50%1/2
$$cell_range[1] || 1
l!l
012
MC/DC0%0/1
$$cell_range[1] || 1
$$cell_range[1]
Truth table50%1/2
A
A= $$cell_range[1]
Aresult
11
00
104 12 ▶ return if $col_range->[1]->[1] && $cell_range->[1] > $col_range->[1]->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $$col_range[1][1] and $$cell_range[1] > $$col_range[1][1] 0 12 12
Condition33%1/3
$$col_range[1][1] and $$cell_range[1] > $$col_range[1][1]
!ll&&!rl&&r
0120
MC/DC0%0/2
$$col_range[1][1] and $$cell_range[1] > $$col_range[1][1]
$$col_range[1][1] $$cell_range[1] > $$col_range[1][1]
Truth table33%1/3
A and B
A= $$col_range[1][1]B= $$cell_range[1] > $$col_range[1][1]
ABresult
0X0
100
111
105  
106 12 my $cell = Cell->new(worksheet => $self->worksheet(), range => $cell_range);
107 12 $cell->share_values($self);
108 12 return $cell;
109 }
110  
111 21 ▶sub is_other_inside {
Subroutine is_other_inside: called CC=7 SCAR=19.6
Pod documented
112 21 my $self = shift;
113  
114 21 state $check = signature(positional => [HasRange]);
115 21 my ($inside_range) = $check->(@_);
116  
117 21 my $range = $self->range_to_hash($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED);
118 21 $inside_range = $inside_range->range_to_hash($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED); # can't use aliased.
119  
120 21 ▶ return if $range->[0]->{col} < $inside_range->[0]->{col};
Branch: 1 branch
BranchTrueFalseTotal
if $$range[0]{"col"} < $$inside_range[0]{"col"} 3 18 21
121 18 ▶ return if $range->[1]->{col} > $inside_range->[1]->{col};
Branch: 1 branch
BranchTrueFalseTotal
if $$range[1]{"col"} > $$inside_range[1]{"col"} 0 18 18
122 18 ▶ return if $range->[0]->{row} && $range->[0]->{row} > $inside_range->[0]->{row};
Branch: 1 branch
BranchTrueFalseTotal
if $$range[0]{"row"} and $$range[0]{"row"} > $$inside_range[0]{"row"} 2 16 18
Condition100%3/3
$$range[0]{"row"} and $$range[0]{"row"} > $$inside_range[0]{"row"}
!ll&&!rl&&r
1332
MC/DC100%2/2
$$range[0]{"row"} and $$range[0]{"row"} > $$inside_range[0]{"row"}
$$range[0]{"row"} $$range[0]{"row"} > $$inside_range[0]{"row"}
Truth table100%3/3
A and B
A= $$range[0]{"row"}B= $$range[0]{"row"} > $$inside_range[0]{"row"}
ABresult
0X0
100
111
123 16 ▶ return if $range->[1]->{row} && $range->[1]->{row} < $inside_range->[1]->{row};
Branch: 1 branch
BranchTrueFalseTotal
if $$range[1]{"row"} and $$range[1]{"row"} < $$inside_range[1]{"row"} 0 16 16
Condition66%2/3
$$range[1]{"row"} and $$range[1]{"row"} < $$inside_range[1]{"row"}
!ll&&!rl&&r
1420
MC/DC0%0/2
$$range[1]{"row"} and $$range[1]{"row"} < $$inside_range[1]{"row"}
$$range[1]{"row"} $$range[1]{"row"} < $$inside_range[1]{"row"}
Truth table66%2/3
A and B
A= $$range[1]{"row"}B= $$range[1]{"row"} < $$inside_range[1]{"row"}
ABresult
0X0
100
111
124
125 16 return 1;
126 }
127  
128 0 ▶sub freeze {
Subroutine freeze: not called CC=1 SCAR=6.9
Pod undocumented
129 0 my $self = shift;
130 0 my $range = $self->range_to_dimension('col');
131 0 return $self->freeze_cols($range->{endIndex});
132 }
133  
134 0 ▶sub thaw {
Subroutine thaw: not called CC=1 SCAR=6.9
Pod undocumented
135 0 my $self = shift;
136 0 my $range = $self->range_to_dimension('col');
137 0 return $self->freeze_cols($range->{startIndex});
138 }
139  
140 0 ▶sub heading { shift->SUPER::heading(@_)->right()->freeze(); }
Subroutine heading: not called CC=1 SCAR=6.9
Pod undocumented
141 0 ▶sub insert_d { shift->insert_dimension(inherit => shift); }
Subroutine insert_d: not called CC=1 SCAR=6.9
Pod undocumented
142 0 ▶sub insert_dimension { shift->SUPER::insert_dimension(dimension => 'col', @_); }
Subroutine insert_dimension: not called CC=1 SCAR=6.9
Pod undocumented
143 0 ▶sub move_dimension { shift->SUPER::move_dimension(dimension => 'col', @_); }
Subroutine move_dimension: not called CC=1 SCAR=6.9
Pod undocumented
144 0 ▶sub delete_dimension { shift->SUPER::delete_dimension(dimension => 'col', @_); }
Subroutine delete_dimension: not called CC=1 SCAR=6.9
Pod undocumented
145  
146 2 1;
147  
148 __END__
« RestApi/DocsApi1.pm ↑ Summary RestApi/SheetsApi4/Range/Row.pm »