The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

GRNOC::WebService::Client::Paginator

SYNOPSIS

use GRNOC::WebService::Client;

my $websvc = GRNOC::WebService::Client->new( ..., use_pagination => 1 );

# returns a GRNOC::WebService::Client::Paginator object my $paginator = $websvc->get_stuff();

while ( $paginator->has_page() ) {

    my $page = $paginator->next_page();

    if ( !$page || $page->{'error'} ) {

      # handle error
    }
}
                                             

DESCRIPTION

This library acts as an iterator to help properly paginating through a set of GRNOC WebService results. It passes the correct limit & offset values for each iteration after determing the total number of available results from the first response. You probably shouldn't ever instantiate this object yourself directly, but will get an instance of it from the GRNOC::WebService::Client object when it has pagination enabled.

CONSTRUCTOR

new ( OPTIONS )
websvc <GRNOC::WebService::Client> [required]

The GRNOC::WebService::Client object used to issue webservice requests.

limit <NUMBER> [optional]

The maximum number of results to return per each iteration. Defaults to 1000.

offset <NUMBER> [optional]

The initial index to offset the results by. Defaults to 0.

method <STRING> [required]

The name of the webservice method to execute.

params <HASHREF> [optional]

Any additional parameters/key-value pairs to pass to the webservice method.

GETTERS/SETTERS

websvc <GRNOC::WebService::Client>

The GRNOC::WebService::Client object used to issue webservice requests.

total <NUMBER>

The number of known total results for the entire webservice request (non-paginated).

limit <NUMBER>

The maximum number of results to return per each iteration.

offset <NUMBER>

The initial index to offset the results by

method <STRING>

The name of the webservice method to execute.

params <HASHREF>

Any additional parameters/key-value pairs to pass to the webservice method.

METHODS

has_page ()

Returns a true or false value if there are still any pages of results left to return. This will always return true before the first call to next_page() until it knows the total number of possible results.

next_page ()

Returns the response from the webservice call for the next set of paginated results. It will return undef if there was an error attempting to issue the HTTP request. The offset of the paginator will be increased by the size of the limit for the next time it is called.