File Coverage

lib/Google/RestApi/SheetsApi4/RangeGroup/Tie/Iterator.pm
Criterion Covered Total %
statement 27 28 96.4
branch 1 2 50.0
condition n/a
subroutine 4 5 80.0
pod 3 3 100.0
total 35 38 92.1


line stmt bran cond sub pod time code
1              
2             our $VERSION = '1.0.2';
3              
4             use Google::RestApi::Setup;
5 1     1   675  
  1         3  
  1         6  
6             use parent qw(Google::RestApi::SheetsApi4::RangeGroup::Iterator);
7 1     1   19631  
  1         2  
  1         9  
8             my $class = shift;
9             state $check = compile_named(
10 1     1 1 4 tied => HashRef,
11 1         9 _extra_ => slurpy Any,
12             );
13             my $p = named_extra($check->(@_));
14              
15 1         1191 my $ptied = delete $p->{tied};
16             my $tied = tied(%$ptied);
17 1         9  
18 1         3 my $ranges = $tied->ranges();
19             my @keys = keys %$ranges;
20 1         7 my @values = values %$ranges;
21 1         6  
22 1         5 my $range_group = $tied->spreadsheet()->range_group(@values);
23             my $self = $class->SUPER::new(
24 1         4 %$p,
25 1         58 range_group => $range_group,
26             );
27              
28             $self->{keys} = \@keys;
29             $self->{tied} = $ptied;
30 1         11  
31 1         3 return bless $self, $class;
32             }
33 1         18  
34             my $self = shift;
35             my $range_group = $self->SUPER::iterate(@_) or return;
36              
37 2     2 1 9 my @ranges = $range_group->ranges();
38 2 50       27 my %ranges = map {
39             $self->{keys}->[$_] => $ranges[$_];
40 2         98 } (0..$#ranges);
41             my $tied = tied( %{ $self->{tied} });
42 2         9 return $tied->default_worksheet()->tie(%ranges);
  6         38  
43             }
44 2         6  
  2         10  
45 2         15 1;
46              
47 0     0 1    
48             =head1 NAME
49              
50             Google::RestApi::SheetsApi4::RangeGroup::Tie::Iterator - An iterator for tied Ranges.
51              
52             =head1 DESCRIPTION
53              
54             A RangeGroup::Tie::Iterator is used to iterate through a tied range group,
55             returning a tied range group of cells, one group at a time.
56              
57             See the description and synopsis at Google::RestApi::SheetsApi4.
58              
59             =head1 SUBROUTINES
60              
61             =over
62              
63             =item new(tied => <hashref>, %args);
64              
65             Creates a new Iterator object for the given tied range group.
66              
67             tied: A hashref tied to the RangeGroup::Tie object.
68              
69             'args' are passed through to the parent RangeGroup::Iterator::new
70             object's routine.
71              
72             You would not normally call this directly, you'd use the RangeGroup::Tie::iterator
73             method to create the iterator object for you.
74              
75             =item iterate();
76              
77             Return the next group of tied cells in the iteration sequence.
78              
79             =back
80              
81             =head1 AUTHORS
82              
83             =over
84              
85             =item
86              
87             Robin Murray mvsjes@cpan.org
88              
89             =back
90              
91             =head1 COPYRIGHT
92              
93             Copyright (c) 2021, Robin Murray. All rights reserved.
94              
95             This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.