TT#68300 NGCP::API::Client: Track the current iterator in next_page()

We need to track whether we are within the current iterator by using an
additional variable.

Ideally we'd use a proper iterator object that is independent from the
object state, but this should do for now and fixes the regression.

Change-Id: Icc8d06f55277f49ef67fbd023fd53daa22962bce
Fixes: commit 155873d532
changes/70/34270/1
Guillem Jover 6 years ago
parent d5e57595d4
commit bc3f7975fb

@ -139,7 +139,7 @@ sub next_page {
my ($self, $uri) = @_; my ($self, $uri) = @_;
my $collection_url; my $collection_url;
if ($self->{_collection_url}) { if ($self->{_collection_iter}) {
$collection_url = $self->{_collection_url}; $collection_url = $self->{_collection_url};
} else { } else {
$collection_url = $self->_get_url($uri); $collection_url = $self->_get_url($uri);
@ -150,11 +150,16 @@ sub next_page {
$collection_url->query_form(\%params); $collection_url->query_form(\%params);
$self->{_collection_url} = $collection_url; $self->{_collection_url} = $collection_url;
$self->{_collection_iter} = 1;
} }
return unless $self->{_collection_url};
my $req = $self->_create_req('GET', $collection_url); my $req = $self->_create_req('GET', $collection_url);
my $res = NGCP::API::Client::Result->new($self->{_ua}->request($req)); my $res = NGCP::API::Client::Result->new($self->{_ua}->request($req));
undef $self->{_collection_url};
my $data = $res->as_hash(); my $data = $res->as_hash();
if ($data && ref($data) eq 'HASH') { if ($data && ref($data) eq 'HASH') {
my $new_url = URI->new($data->{_links}->{next}->{href}); my $new_url = URI->new($data->{_links}->{next}->{href});
@ -166,8 +171,6 @@ sub next_page {
$new_url->query_form(\%params); $new_url->query_form(\%params);
$self->{_collection_url} = $self->_get_url($new_url->canonical); $self->{_collection_url} = $self->_get_url($new_url->canonical);
} else {
undef $self->{_collection_url};
} }
return $res; return $res;
@ -178,6 +181,7 @@ sub set_page_rows {
$self->{_opts}{page_rows} = $rows; $self->{_opts}{page_rows} = $rows;
undef $self->{_collection_url}; undef $self->{_collection_url};
undef $self->{_collection_iter};
return; return;
} }

Loading…
Cancel
Save