NAME

DigitalOcean::Collection - Represents a Collection object in the DigitalOcean API

VERSION

version 0.17

SYNOPSIS

    FILL ME IN   

DESCRIPTION

FILL ME IN

METHODS

objects

This method returns the objcets for the current page that the collection is on.

    for my $obj (@{$collection->objects}) { 
        #do something with $obj
    } 

cur_page

This method returns the current page number that this collection is on. 0 is the default value.

last_page

This method returns the last page number of this collection is on. 1 is the default value.

params

This method is used to set the parameters in the URLs used to request the next set of objects in the collection. This should not be called by the user directly, but rather will be passed in by DigitalOcean when a subroutine that returns a collection is called. It should be passed in when the DigitalOcean::Collection object is created, because it will mess with the paging of the objects if changed after paging has begun.

    my $do_collection = DigitalOcean::Collection->new(params => {per_page => 2});

pages

This method returns the current DigitalOcean::Pages object that is associated with the "cur_page"

next_element

This method returns the index of the next element to be retrieved within the current array of "objects". If it is greater than the last index of "objects", then the next page will be requested if there is one.

total

This method returns the total number of objects in this collection.

init_objects

This should be set when creating the DigitalOcean::Collection. The format is

    ArrayRef[ArrayRef]

Where the inner array references are of this format:

    ['name_of_setter_method', 'value to set the setter method to'].

Since DigitalOcean::Collection classes are generic and can hold any object, this can be used to initialize the setter method of all objects in the collection to a certain value. For example, if you wanted a collection of DigitalOcean::Domain objects to have their DigitalOcean property set to the DigitalOcean object, you could do this when creating the collection:

    my $collection = DigitalOcean::Collection->new(
        init_objects => [['DigitalOcean', $do]],
        ... #other initialization stuff
    );

This is mainly just for use by the DigitalOcean module when creating DigitalOcean::Collections.

next

This method will return the next object in the collection, and will return undef when there are no more objects in the collection. The "next" method automatically makes requests to the Digital Ocean API when it is time to get the next set of elements on the next page.

    my $obj;
    while($obj = $do_collection->next) { 
        print $obj->id . "\n";
    }

    #now went through entire collection and $obj holds undef

id

AUTHOR

Adam Hopkins <srchulo@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2019 by Adam Hopkins.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.