/usr/lib/perl5/DR/Tarantool/SyncClient.pm is in libdr-tarantool-perl 0.42-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | use utf8;
use strict;
use warnings;
package DR::Tarantool::SyncClient;
use base 'DR::Tarantool::AsyncClient';
use AnyEvent;
use Devel::GlobalDestruction;
use Carp;
$Carp::Internal{ (__PACKAGE__) }++;
=head1 NAME
DR::Tarantool::SyncClient - a synchronous driver for
L<Tarantool|http://tarantool.org>.
=head1 SYNOPSIS
my $client = DR::Tarantool::SyncClient->connect(
port => $tnt->primary_port,
spaces => $spaces
);
if ($client->ping) { .. };
my $t = $client->insert(
first_space => [ 1, 'val', 2, 'test' ], TNT_FLAG_RETURN
);
$t = $client->call_lua('luafunc' => [ 0, 0, 1 ], 'space_name');
$t = $client->select(space_name => $key);
$t = $client->update(space_name => 2 => [ name => set => 'new' ]);
$client->delete(space_name => $key);
=head1 METHODS
=head2 connect
Connects to the server.
=head3 Arguments
The same as L<DR::Tarantool::AsyncClient/connect>, excluding the callback.
Returns a connection handle or croaks an error.
=head3 Additional arguments
=over
=item raise_error
If B<true> (default behaviour) the driver throws an exception for each
error.
=back
=cut
sub connect {
my ($class, %opts) = @_;
my $raise_error = 1;
$raise_error = delete $opts{raise_error} if exists $opts{raise_error};
my $cv = condvar AnyEvent;
my $self;
$class->SUPER::connect(%opts, sub {
($self) = @_;
$cv->send;
});
$cv->recv;
unless(ref $self) {
croak $self if $raise_error;
$! = $self;
return undef;
}
$self->{raise_error} = $raise_error ? 1 : 0;
$self;
}
=head2 ping
The same as L<DR::Tarantool::AsyncClient/ping>, excluding the callback.
Returns B<true> on success, b<false> in case of an error.
=head2 insert
The same as L<DR::Tarantool::AsyncClient/insert>, excluding the callback.
Returns the inserted tuple.
Croaks error if an error occurred (as long as B<raise_error> is true).
=head2 select
The same as L<DR::Tarantool::AsyncClient/select>, excluding the callback.
Returns tuples contained in the server response or undef.
Croaks error if an error occurred (as long as B<raise_error> is true).
=head2 update
The same as L<DR::Tarantool::AsyncClient/update>, excluding the callback.
Returns the updated tuple.
Croaks error if an error occurred (as long as B<raise_error> is true).
=head2 delete
The same as L<DR::Tarantool::AsyncClient/delete>, excluding the callback.
Returns the deleted tuple or undef.
Croaks error if an error occurred (as long as B<raise_error> is true).
=head2 call_lua
The same as L<DR::Tarantool::AsyncClient/call_lua>, excluding the callback.
Returns tuples contained in the server response or undef.
Croaks error if an error occurred (as long as B<raise_error> is true).
=cut
for my $method (qw(ping insert select update delete call_lua)) {
no strict 'refs';
*{ __PACKAGE__ . "::$method" } = sub {
my ($self, @args) = @_;
my @res;
my $cv = condvar AnyEvent;
my $m = "SUPER::$method";
$self->$m(@args, sub { @res = @_; $cv->send });
$cv->recv;
if ($res[0] eq 'ok') {
return 1 if $method eq 'ping';
return $res[1];
}
return 0 if $method eq 'ping';
return undef unless $self->{raise_error};
croak sprintf "%s: %s",
defined($res[1])? $res[1] : 'unknown',
$res[2]
;
};
}
sub DESTROY {
my ($self) = @_;
return if in_global_destruction;
my $cv = condvar AnyEvent;
$self->disconnect(sub { $cv->send });
$cv->recv;
}
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 Dmitry E. Oboukhov <unera@debian.org>
Copyright (C) 2011 Roman V. Nikolaev <rshadow@rambler.ru>
This program is free software, you can redistribute it and/or
modify it under the terms of the Artistic License.
=head1 VCS
The project is placed git repo on github:
L<https://github.com/dr-co/dr-tarantool/>.
=cut
1;
|