DR-Tarantool
view release on metacpan or search on metacpan
lib/DR/Tarantool/AsyncClient.pm view on Meta::CPAN
my $self;
if (ref $client) {
$self = bless {
llc => $client,
spaces => $spaces,
} => ref($class) || $class;
} else {
$self = $client;
}
$cb->( $self );
}
);
return;
}
=head1 Attributes
=head2 space
Returns a space object by space name or numeric id. See perldoc
L<DR::Tarantool::Spaces> for more details.
=cut
sub space {
my ($self, $name) = @_;
return $self->{spaces}->space($name);
}
sub disconnect {
my ($self, $cb) = @_;
$self->_llc->disconnect( $cb );
}
sub _llc { return $_[0]{llc} if ref $_[0]; return 'DR::Tarantool::LLClient' }
sub _cb_default {
my ($res, $s, $cb) = @_;
if ($res->{status} ne 'ok') {
$cb->($res->{status} => $res->{code}, $res->{errstr});
return;
}
if ($s) {
$cb->( ok => $s->tuple_class->unpack( $res->{tuples}, $s ),
$res->{code}
);
} else {
$cb->( 'ok', $res->{tuples}, $res->{code} );
}
return;
}
=head1 Worker methods
All methods accept callbacks which are invoked with the following arguments:
=over
=item status
On success, this field has value 'B<ok>'. The value
of this parameter determines the contents of the rest of the callback
arguments.
=item a tuple or tuples or an error code
On success, the second argument contains tuple(s) produced by
the request. On error, it contains the server error code.
=item errorstr
Error string in case of an error.
=back
sub {
if ($_[0] eq 'ok') {
my ($status, $tuples) = @_;
...
} else {
my ($status, $code, $errstr) = @_;
}
}
=head2 ping
Ping the server.
$client->ping(sub { ... });
=head3 Arguments
=over
=item cb
=back
=cut
sub ping {
my ($self, $cb, %opts) = &_split_args;
$self->_llc->ping(sub { _cb_default($_[0], undef, $cb) });
}
=head2 insert
Insert a tuple into a space.
$client->insert('space', [ 'user', 10, 'password' ], sub { ... });
$client->insert('space', \@tuple, $flags, sub { ... });
( run in 0.896 second using v1.01-cache-2.11-cpan-39bf76dae61 )