File Coverage

lib/Google/RestApi/SheetsApi4/Range/Iterator.pm
Criterion Covered Total %
statement 3 16 18.7
branch 0 4 0.0
condition 0 5 0.0
subroutine 1 6 16.6
pod 5 5 100.0
total 9 36 25.0


line stmt bran cond sub pod time code
1              
2             our $VERSION = '1.0.2';
3              
4             use Google::RestApi::Setup;
5 1     1   479  
  1         3  
  1         14  
6             my $class = shift;
7             state $check = compile_named(
8 0     0 1   range => HasMethods[qw(range worksheet)],
9 0           dim => StrMatch[qr/^(col|row)$/], { default => 'row' },
10             by => PositiveInt, { default => 1 },
11             from => PositiveOrZeroInt, { optional => 1 },
12             to => PositiveOrZeroInt, { optional => 1 },
13             );
14             my $self = $check->(@_);
15             $self->{current} = delete $self->{from} || 0;
16 0           return bless $self, $class;
17 0   0       }
18 0            
19             my $self = shift;
20             return if defined $self->{to} && $self->{current} + 1 > $self->{to};
21             my $cell = $self->range()->cell_at_offset($self->{current}, $self->{dim});
22 0     0 1   $self->{current} += $self->{by} if $cell;
23 0 0 0       return $cell;
24 0           }
25 0 0          
26 0            
27             1;
28 0     0 1    
29              
30 0     0 1   =head1 NAME
31 0     0 1    
32             Google::RestApi::SheetsApi4::Range::Iterator - An iterator for an arbitrary Range.
33              
34             =head1 DESCRIPTION
35              
36             A Range::Iterator is used to iterate through a range, returning each
37             cell, one at a time.
38              
39             See the description and synopsis at Google::RestApi::SheetsApi4.
40              
41             =head1 SUBROUTINES
42              
43             =over
44              
45             =item new(range => <Range>, dim => <dimension>, by => <int>);
46              
47             Creates a new Iterator object for the given range.
48              
49             range: The Range object for which we are iterating.
50             dim: The direction of the iteration ('col' or 'row'). The default is 'row'.
51             by: The number of cells to skip between each iteration.
52              
53             'dim' is used to specify which major dimension is used for the iteration.
54             For a given range 'A1:B2', a 'dim' of 'col' will return A1, A2, B1, B2
55             for each successive iteration. For a 'dim' of 'row', it will return
56             A1, B1, A2, B2 for each successive iteration.
57              
58             'by' is used to allow you to only return, say, every second cell in the
59             iteration ('by' = '2'). For a given range 'A1:B4' and a 'by' of '2',
60             it will return A1, A3, B1, B3 for each succesive iteration.
61              
62             You would not normally call this directly, you'd use the Range::iterator
63             method to create the iterator object for you.
64              
65             =item iterate();
66              
67             Return the next cell in the iteration sequence.
68              
69             =item next();
70              
71             An alias for iterate().
72              
73             =item range();
74              
75             Returns the Range object for this iterator.
76              
77             =item worksheet();
78              
79             # Returns the Worksheet object for this iterator.
80              
81             =back
82              
83             =head1 AUTHORS
84              
85             =over
86              
87             =item
88              
89             Robin Murray mvsjes@cpan.org
90              
91             =back
92              
93             =head1 COPYRIGHT
94              
95             Copyright (c) 2021, Robin Murray. All rights reserved.
96              
97             This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.