Arango-Tango

 view release on metacpan or  search on metacpan

lib/Arango/Tango/Cursor.pm  view on Meta::CPAN

# ABSTRACT: ArangoDB Cursor object
package Arango::Tango::Cursor;
$Arango::Tango::Cursor::VERSION = '0.013';
use warnings;
use strict;

use Data::Dumper;

sub _new {
  my ($class, %opts) = @_;
  my $self = { arango => $opts{arango}, database => $opts{database} };

  my $ans = $self->{arango}->_api('create_cursor', \%opts);

  return bless { %$ans, %$self, __current => 0 } => $class;
}

sub next {
  my $self = shift;

  if (!$self->{error} && $self->{__current} == 0) {
    $self->{__current}++;
    return $self->{result};
  }

  if ($self->{hasMore}) {
    my $ans = $self->{arango}->_api('cursor_next', { database => $self->{database}, id => $self->{id} });
    if (!$ans->{error}) {
      $self->{hasMore} = $ans->{hasMore};
      return $ans->{result};
    }
  }

  return undef;
}

sub finish {
  my ($self) = @_;
  $self->{arango}->_api('cursor_delete',  { database => $self->{database}, id => $self->{id} });
  delete $self->{$_} for (keys %$self);
}

sub has_more {
  my ($self) = @_;
  return $self->{hasMore};
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Arango::Tango::Cursor - ArangoDB Cursor object

=head1 VERSION

version 0.013

=head1 USAGE

This class should not be created directly. The L<Arango::Tango> module is responsible for
creating instances of this object.

C<Arango::Tango::Cursor> answers to the following methods:

=head1 METHODS

=over 4

=item C<next>

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 0.962 second using v1.00-cache-1.14-grep-28634ff-cpan-207214f8fbd )