From bc3f7975fb86348ba10d0fbbe2a9b4bcca43d179 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 15 Oct 2019 15:54:50 +0200 Subject: [PATCH] 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 155873d532f5362f73eb21c31e3e3961d5440cb4 --- lib/NGCP/API/Client.pm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/NGCP/API/Client.pm b/lib/NGCP/API/Client.pm index cb338c4..a3760a7 100644 --- a/lib/NGCP/API/Client.pm +++ b/lib/NGCP/API/Client.pm @@ -139,7 +139,7 @@ sub next_page { my ($self, $uri) = @_; my $collection_url; - if ($self->{_collection_url}) { + if ($self->{_collection_iter}) { $collection_url = $self->{_collection_url}; } else { $collection_url = $self->_get_url($uri); @@ -150,11 +150,16 @@ sub next_page { $collection_url->query_form(\%params); $self->{_collection_url} = $collection_url; + $self->{_collection_iter} = 1; } + return unless $self->{_collection_url}; + my $req = $self->_create_req('GET', $collection_url); my $res = NGCP::API::Client::Result->new($self->{_ua}->request($req)); + undef $self->{_collection_url}; + my $data = $res->as_hash(); if ($data && ref($data) eq 'HASH') { my $new_url = URI->new($data->{_links}->{next}->{href}); @@ -166,8 +171,6 @@ sub next_page { $new_url->query_form(\%params); $self->{_collection_url} = $self->_get_url($new_url->canonical); - } else { - undef $self->{_collection_url}; } return $res; @@ -178,6 +181,7 @@ sub set_page_rows { $self->{_opts}{page_rows} = $rows; undef $self->{_collection_url}; + undef $self->{_collection_iter}; return; }