This file is indexed.

/usr/lib/perl5/DR/Tarantool/RealSyncClient.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
use utf8;
use strict;
use warnings;

package DR::Tarantool::RealSyncClient;


=head1 NAME

DR::Tarantool::RealSyncClient - a synchronous driver for L<Tarantool/Box|http://tarantool.org>

=head1 SYNOPSIS

    my $client = DR::Tarantool::RealSyncClient->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 DESCRIPTION

The module is a clone of L<DR::Tarantool::SyncClient> but it doesn't
use L<AnyEvent> or L<Coro>.

The module uses L<IO::Socket> sockets.

=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

use DR::Tarantool::LLSyncClient;
use DR::Tarantool::Spaces;
use DR::Tarantool::Tuple;
use Carp;
$Carp::Internal{ (__PACKAGE__) }++;
use Data::Dumper;
use Scalar::Util 'blessed';

my $unpack = sub {
    my ($self, $res, $s) = @_;
    return undef unless $res and $res->{status} eq 'ok';
    return $s->tuple_class->unpack( $res->{tuples}, $s ) if $s;
    return $res->{tuples};
};

sub connect {
    my ($class, %opts) = @_;

    my $host = $opts{host} || 'localhost';
    my $port = $opts{port} or croak "port isn't defined";

    my $spaces = blessed($opts{spaces}) ?
        $opts{spaces} : DR::Tarantool::Spaces->new($opts{spaces});
    my $reconnect_period    = $opts{reconnect_period} || 0;
    my $reconnect_always    = $opts{reconnect_always} || 0;

    my $client = DR::Tarantool::LLSyncClient->connect(
        host                => $host,
        port                => $port,
        reconnect_period    => $reconnect_period,
        reconnect_always    => $reconnect_always,
        exists($opts{raise_error}) ?
            (   raise_error => $opts{raise_error} ?  1: 0 )
            : (),
    );


    return undef unless $client;
    return bless { llc => $client, spaces => $spaces } => ref($class) || $class;
}

sub space {
    my ($self, $name) = @_;
    return $self->{spaces}->space($name);
}


sub ping {
    my ($self) = @_;
    $self->{llc}->ping;
}

sub insert {
    my $self = shift;
    my $space = shift;
    $self->_llc->_check_tuple( my $tuple = shift );
    my $flags = pop || 0;

    my $s = $self->{spaces}->space($space);

    my $res =
        $self->_llc->insert( $s->number, $s->pack_tuple( $tuple ), $flags );
    return $unpack->($self, $res, $s);
}

sub call_lua {
    my $self = shift;
    my $lua_name = shift;
    my $args = shift;

    unshift @_ => 'space' if @_ == 1;
    my %opts = @_;

    my $flags = $opts{flags} || 0;
    my $space_name = $opts{space};
    my $fields = $opts{fields};

    my $s;
    croak "You can't use 'fields' and 'space' at the same time"
        if $fields and $space_name;

    if ($space_name) {
        $s = $self->space( $space_name );
    } elsif ( $fields ) {
        $s = DR::Tarantool::Space->new(
            0 =>
            {
                name    => 'temp_space',
                fields  => $fields,
                indexes => {}
            },
        );
    } else {
        $s = DR::Tarantool::Space->new(
            0 =>
            {
                name            => 'temp_space',
                fields          => [],
                indexes         => {}
            },
        );
    }

    if ($opts{args}) {
        my $sa = DR::Tarantool::Space->new(
            0 =>
            {
                name    => 'temp_space_args',
                fields  => $opts{args},
                indexes => {}
            },
        );
        $args = $sa->pack_tuple( $args );
    }

    my $res = $self->_llc->call_lua( $lua_name, $args, $flags );

    return $unpack->($self, $res, $s);
}


sub select {
    my $self = shift;
    my $space = shift;
    my $keys = shift;

    my ($index, $limit, $offset);

    if (@_ == 1) {
        $index = shift;
    } elsif (@_ == 3) {
        ($index, $limit, $offset) = @_;
    } elsif (@_) {
        my %opts = @_;
        $index = $opts{index};
        $limit = $opts{limit};
        $offset = $opts{offset};
    }

    $index ||= 0;

    my $s = $self->space($space);

    my $res = $self->_llc->select(
        $s->number,
        $s->_index( $index )->{no},
        $s->pack_keys( $keys, $index ),
        $limit,
        $offset
    );

    return $unpack->($self, $res, $s);
}

sub update {
    my $self = shift;
    my $space = shift;
    my $key = shift;
    my $op = shift;
    my $flags = shift || 0;

    my $s = $self->space($space);

    my $res = $self->_llc->update(
        $s->number,
        $s->pack_primary_key( $key ),
        $s->pack_operations( $op ),
        $flags,
    );
    return $unpack->($self, $res, $s);
}

sub delete :method {
    my $self = shift;
    my $space = shift;
    my $key = shift;
    my $flags = shift || 0;

    my $s = $self->space($space);

    my $res = $self->_llc->delete(
        $s->number,
        $s->pack_primary_key( $key ),
        $flags,
    );
    return $unpack->($self, $res, $s);
}

sub last_code { $_[0]->{llc}->last_code }
sub last_error_string { $_[0]->{llc}->last_error_string }
sub raise_error { $_[0]->raise_error };
sub _llc { $_[0]{llc} }

1;