File Coverage

lib/Google/RestApi/SheetsApi4/Range/Cell.pm
Criterion Covered Total %
statement 40 45 88.8
branch 10 12 83.3
condition 1 3 33.3
subroutine 11 13 84.6
pod 4 5 80.0
total 66 78 84.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   465  
  1         3  
  1         6  
6             use Try::Tiny qw( try catch );
7 1     1   18912  
  1         3  
  1         43  
8             use aliased 'Google::RestApi::SheetsApi4::Range';
9 1     1   5  
  1         2  
  1         5  
10             use parent Range;
11 1     1   168  
  1         4  
  1         5  
12             # make sure the translated range refers to a single cell (no ':').
13             my $class = shift;
14             my %self = @_;
15 135     135 1 334  
16 135         503 # this is fucked up, but want to support creating this object directly and also
17             # via the range::factory method, so have to handle both cases here. try to create
18             # the cell directly first (which could also come via the factory method, which will
19             # have already translated the address into a cell), and failing that, see if the
20             # range factory can create a cell (which will resolve any named or header references).
21             # this has the potential of looping between this and factory method.
22              
23             # if factory has already been used, then this should resolve here.
24             my $err;
25             try {
26 135         243 state $check = compile(RangeCell);
27             ($self{range}) = $check->($self{range});
28 135     135   6829 } catch {
29 135         119232 $err = $_;
30             };
31 2     2   182 return $class->SUPER::new(%self) if !$err;
32 135         1498  
33 135 100       7111 # see if the range passed can be translated to what we want via the factory.
34             my $factory_range;
35             try {
36 2         13 $factory_range = Google::RestApi::SheetsApi4::Range::factory(%self);
37             } catch {};
38 2     2   76 return $factory_range if $factory_range && $factory_range->isa(__PACKAGE__);
39 2     0   14  
40 2 50 33     44 LOGDIE sprintf("Unable to translate '%s' into a worksheet cell: $err", flatten_range($self{range}));
41             }
42 0         0  
43             my $self = shift;
44             state $check = compile_named(
45             values => Str, { optional => 1 },
46 101     101 1 172 _extra_ => slurpy Any,
47 101         150 );
48             my $p = named_extra($check->(@_));
49             $p->{values} = [[ $p->{values} ]] if defined $p->{values};
50             my $values = $self->SUPER::values(%$p);
51 101         1026 return defined $values ? $values->[0]->[0] : undef;
52 101 50       285 }
53 101         375  
54 101 100       716 my $self = shift;
55              
56             state $check = compile_named(
57             values => Str, { optional => 1 },
58 36     36 1 60 );
59             my $p = $check->(@_);
60 36         52  
61             $p->{values} = [[ $p->{values} ]] if $p->{values};
62             return $self->SUPER::batch_values(%$p);
63 36         806 }
64              
65 36 100       550 # is this 0 or infinity? return self if offset is 0, undef otherwise.
66 36         134 my $self = shift;
67             state $check = compile(Int, DimColRow, { optional => 1 });
68             my ($offset) = $check->(@_); # we're a cell, no dim required.
69             return $self if !$offset;
70             return;
71 4     4 0 350 }
72 4         10  
73 4         1226 my $self = shift;
74 4 100       117 state $check = compile(HasRange);
75 2         7 my ($inside_range) = $check->(@_);
76             return $self->range() eq $inside_range->range();
77             }
78              
79 0     0 1   1;
80 0            
81 0            
82 0           =head1 NAME
83              
84             Google::RestApi::SheetsApi4::Range::Cell - Represents a cell within a Worksheet.
85              
86             =head1 DESCRIPTION
87              
88             A Range::Cell object modifies the behaviour of the parent Range object
89             to treat the values used within the range as a plain string instead of
90             arrays of arrays. This object will encapsulate the passed string value
91             into a [[$value]] array of arrays when interacting with Goolge API.
92              
93             See the description and synopsis at Google::RestApi::SheetsApi4.
94              
95             =head1 AUTHORS
96              
97             =over
98              
99             =item
100              
101             Robin Murray mvsjes@cpan.org
102              
103             =back
104              
105             =head1 COPYRIGHT
106              
107             Copyright (c) 2021, Robin Murray. All rights reserved.
108              
109             This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.