DR-Tarantool
view release on metacpan or search on metacpan
lib/DR/Tarantool/AEConnection.pm view on Meta::CPAN
$self->{errno} = $errno;
$self->{on}{error}($self);
$self->{guard} = {};
$self->{wbuf} = '';
$self->_check_reconnect;
}
sub _check_reconnect {
Scalar::Util::weaken(my $self = shift);
return if $self->state eq 'connected';
return if $self->state eq 'connecting';
return if $self->{guard}{rc};
return unless $self->reconnect_period;
unless ($self->reconnect_always) {
return unless $self->{success_connects};
}
$self->{guard}{rc} = AE::timer $self->reconnect_period, 0, sub {
return unless $self;
delete $self->{guard}{rc};
$self->{on}{reconnecting}($self);
$self->connect;
};
}
sub connect {
Scalar::Util::weaken(my $self = shift);
return if $self->state eq 'connected' or $self->state eq 'connecting';
$self->{state} = 'connecting';
$self->{error} = undef;
$self->{errno} = undef;
$self->{guard} = {};
$self->{guard}{c} = AnyEvent::Socket::tcp_connect
$self->host,
lib/DR/Tarantool/AEConnection.pm view on Meta::CPAN
$self->{guard} = {};
$self->{on}{connfail}($self);
$self->_check_reconnect;
};
}
$self;
}
sub disconnect {
Scalar::Util::weaken(my $self = shift);
return if $self->state eq 'disconnect' or $self->state eq 'init';
$self->{guard} = {};
$self->{error} = 'Disconnected';
$self->{errno} = 'SUCCESS';
$self->{state} = 'disconnect';
$self->{wbuf} = '';
$self->{on}{disconnect}($self);
}
sub push_write {
Scalar::Util::weaken(my $self = shift);
my ($str) = @_;
$self->{wbuf} .= $str;
return unless $self->state eq 'connected';
return unless length $self->{wbuf};
return if $self->{guard}{write};
$self->{guard}{write} = AE::io $self->fh, 1, sub {
my $l = syswrite $self->fh, $self->{wbuf};
lib/DR/Tarantool/LLClient.pm view on Meta::CPAN
package DR::Tarantool::LLClient;
use base qw(DR::Tarantool::AEConnection);
use AnyEvent;
use AnyEvent::Socket;
use Carp;
use Devel::GlobalDestruction;
use File::Spec::Functions 'catfile';
$Carp::Internal{ (__PACKAGE__) }++;
use Scalar::Util 'weaken';
require DR::Tarantool;
use Data::Dumper;
use Time::HiRes ();
my $LE = $] > 5.01 ? '<' : '';
=head2 connect
Creates a connection to L<Tarantool| http://tarantool.org>
lib/DR/Tarantool/LLClient.pm view on Meta::CPAN
$cb->({
status => 'fatal',
req_id => $id,
errstr => "Connection isn't established (yet)"
}
);
return;
}
my $this = $self;
weaken $this;
my $tmr;
$tmr = AE::timer $self->reconnect_period, 0, sub {
undef $tmr;
if ($this and $this->is_connected) {
$this->_request( $id, $pkt, $cb );
return;
}
$cb->({
status => 'fatal',
lib/DR/Tarantool/LLClient.pm view on Meta::CPAN
print $fh $res_pkt;
close $fh;
}
};
warn $@ if $@;
}
sub _request {
my ($self, $id, $pkt, $cb ) = @_;
# Scalar::Util::weaken $self;
my $cbres = $cb;
$cbres = sub { $self->_log_transaction($id, $pkt, @_); &$cb }
if $ENV{TNT_LOG_ERRDIR} or $ENV{TNT_LOG_DIR};
$self->{ wait }{ $id } = $cbres;
$self->push_write($pkt);
}
lib/DR/Tarantool/Tuple.pm view on Meta::CPAN
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);
( run in 0.341 second using v1.01-cache-2.11-cpan-65fba6d93b7 )