DR-Tarantool
view release on metacpan or search on metacpan
lib/DR/Tarantool/Tuple.pm view on Meta::CPAN
use utf8;
use strict;
use warnings;
=head1 NAME
DR::Tarantool::Tuple - a tuple container for L<DR::Tarantool>
=head1 SYNOPSIS
my $tuple = new DR::Tarantool::Tuple([ 1, 2, 3]);
my $tuple = new DR::Tarantool::Tuple([ 1, 2, 3], $space);
my $tuple = unpack DR::Tarantool::Tuple([ 1, 2, 3], $space);
$tuple->next( $other_tuple );
$f = $tuple->raw(0);
$f = $tuple->name_field;
=head1 DESCRIPTION
A tuple contains normalized (unpacked) fields. You can access the fields
by their indexes (see L<raw> function) or by their names (if they are
described in the space).
Each tuple can contain references to L<next> tuple and L<iter>ator,
so that if the server returns more than one tuple, all of them
can be accessed.
=head1 METHODS
=cut
package DR::Tarantool::Tuple;
use DR::Tarantool::Iterator;
use Scalar::Util 'weaken', 'blessed';
use Carp;
$Carp::Internal{ (__PACKAGE__) }++;
=head2 new
A constructor.
my $t = DR::Tarantool::Tuple->new([1, 2, 3]);
my $t = DR::Tarantool::Tuple->new([1, 2, 3], $space);
=cut
sub new :method {
my ($class, $tuple, $space) = @_;
$class = ref $class if ref $class;
# hack to replace default autoload
$class = $space->tuple_class if $space and $class eq __PACKAGE__;
croak 'wrong space' if defined $space and !blessed $space;
croak 'tuple must be ARRAYREF [of ARRAYREF]' unless 'ARRAY' eq ref $tuple;
croak "tuple can't be empty" unless @$tuple;
$tuple = [ $tuple ] unless 'ARRAY' eq ref $tuple->[0];
my $iterator = DR::Tarantool::Iterator->new(
$tuple,
data => $space,
item_class => ref($class) || $class,
item_constructor => '_new'
);
return bless {
idx => 0,
iterator => $iterator,
} => ref($class) || $class;
}
sub _new {
my ($class, $item, $idx, $iterator) = @_;
return bless {
idx => $idx,
iterator => $iterator,
} => ref($class) || $class;
}
=head2 unpack
Another way to construct a tuple.
my $t = DR::Tarantool::Tuple->unpack([1, 2, 3], $space);
=cut
sub unpack :method {
( run in 0.779 second using v1.01-cache-2.11-cpan-39bf76dae61 )