File Coverage

lib/Google/RestApi/SheetsApi4/Range/Row.pm
Criterion Covered Total %
statement 60 71 84.5
branch 17 20 85.0
condition 9 14 64.2
subroutine 13 21 61.9
pod 4 12 33.3
total 103 138 74.6


line stmt bran cond sub pod time code
1              
2             our $VERSION = '1.0.2';
3              
4             use Google::RestApi::Setup;
5 1     1   541  
  1         3  
  1         5  
6             use Try::Tiny qw( try catch );
7 1     1   18927  
  1         2  
  1         42  
8             use aliased 'Google::RestApi::SheetsApi4::Range';
9 1     1   6 use aliased 'Google::RestApi::SheetsApi4::Range::Cell';
  1         2  
  1         5  
10 1     1   150  
  1         2  
  1         5  
11             use parent Range;
12 1     1   146  
  1         2  
  1         5  
13             my $class = shift;
14             my %self = @_;
15 40     40 1 94  
16 40         175 $self{dim} = 'row';
17              
18 40         130 # this is fucked up, but want to support creating this object directly and also
19             # via the range::factory method, so have to handle both cases here. try to create
20             # the row directly first (which could also come via the factory method, which will
21             # have already translated the address into a row), and failing that, see if the
22             # range factory can create a row (which will resolve any named or header references).
23             # this has the potential of looping between this and factory method.
24              
25             # if factory has already been used, then this should resolve here.
26             my $err;
27             try {
28 40         86 state $check = compile(RangeRow);
29             ($self{range}) = $check->($self{range});
30 40     40   2265 } catch {
31 40         39935 $err = $_;
32             };
33 6     6   720 return $class->SUPER::new(%self) if !$err;
34 40         469  
35 40 100       3401 # see if the range passed can be translated to what we want via the factory.
36             my $factory_range;
37             try {
38 6         46 $factory_range = Google::RestApi::SheetsApi4::Range::factory(%self);
39             } catch {};
40 6     6   263 return $factory_range if $factory_range && $factory_range->isa(__PACKAGE__);
41 6     0   41  
42 6 100 66     179 LOGDIE sprintf("Unable to translate '%s' into a worksheet row: $err", flatten_range($self{range}));
43             }
44 2         13  
45             my $self = shift;
46             state $check = compile_named(
47             values => ArrayRef[Str], { optional => 1 },
48 18     18 1 37 _extra_ => slurpy Any,
49 18         35 );
50             my $p = named_extra($check->(@_));
51             $p->{values} = [ $p->{values} ] if defined $p->{values};
52             my $values = $self->SUPER::values(%$p);
53 18         1108 return defined $values ? $values->[0] : undef;
54 18 100       67 }
55 18         73  
56 18 100       108 my $self = shift;
57             state $check = compile_named(
58             values => ArrayRef[Str], { optional => 1 },
59             );
60 12     12 1 19 my $p = $check->(@_);
61 12         21 $p->{values} = [ $p->{values} ] if $p->{values};
62             return $self->SUPER::batch_values(%$p);
63             }
64 12         904  
65 12 100       186 my $self = shift;
66 12         50  
67             state $check = compile(Int, DimColRow, { optional => 1 });
68             my ($offset) = $check->(@_); # we're a column, no dim required.
69              
70 6     6 0 652 my $row_range = $self->range_to_array($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED); # can't use aliased
71             my $cell_range = $row_range->[0];
72 6         15 $cell_range->[0] = ($cell_range->[0] || 1) + $offset;
73 6         1248 return if $row_range->[1]->[0] && $cell_range->[0] > $row_range->[1]->[0];
74              
75 6         176 my $cell = Cell->new(worksheet => $self->worksheet(), range => $cell_range);
76 6         15 $cell->share_values($self);
77 6   50     24 return $cell;
78 6 50 33     33 }
79              
80 6         18 my $self = shift;
81 6         24  
82 6         28 state $check = compile(HasRange);
83             my ($inside_range) = $check->(@_);
84              
85             my $range = $self->range_to_hash($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED);
86 15     15 1 107 $inside_range = $inside_range->range_to_hash($Google::RestApi::SheetsApi4::Range::RANGE_EXPANDED); # can't use aliased.
87              
88 15         37 return if $range->[0]->{row} ne $inside_range->[0]->{row};
89 15         725 return if $range->[1]->{row} ne $inside_range->[1]->{row};
90             return if $range->[0]->{col} && $range->[0]->{col} > $inside_range->[0]->{col};
91 15         299 return if $range->[1]->{col} && $range->[1]->{col} < $inside_range->[1]->{col};
92 15         61
93             return 1;
94 15 100       122 }
95 12 50       67  
96 12 100 100     103 my $self = shift;
97 10 50 66     51 my $range = $self->range_to_dimension('row');
98             return $self->freeze_rows($range->{endIndex});
99 10         52 }
100              
101             my $self = shift;
102             my $range = $self->range_to_dimension('row');
103 0     0 0   return $self->freeze_rows($range->{startIndex});
104 0           }
105 0            
106              
107             1;
108              
109 0     0 0    
110 0           =head1 NAME
111 0            
112             Google::RestApi::SheetsApi4::Range::Row - Represents a row within a Worksheet.
113              
114 0     0 0   =head1 DESCRIPTION
115 0     0 0    
116 0     0 0   A Range::Row object modifies the behaviour of the parent Range object
117 0     0 0   to treat the values used within the range as a row in the spreadsheet,
118 0     0 0   in other words, a single flat array instead of arrays of arrays. This
119             object will encapsulate the passed flat array value into a [$value]
120             array of arrays when interacting with Google API.
121              
122             It also adjusts calls defined in Request::Spreadsheet::Worksheet::Range
123             to reflect using a row instead of a general range.
124              
125             See the description and synopsis at Google::RestApi::SheetsApi4.
126              
127             =head1 AUTHORS
128              
129             =over
130              
131             =item
132              
133             Robin Murray mvsjes@cpan.org
134              
135             =back
136              
137             =head1 COPYRIGHT
138              
139             Copyright (c) 2021, Robin Murray. All rights reserved.
140              
141             This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.