blib/lib/DR/Tarantool/MsgPack/SyncClient.pm untested

filter: Statementstmt 0.0% 0 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 80 CC 4 SCAR 15.9
CC
4
Cov
0%
connect
12.0
ping
6.0
BEGIN
2.0
CRAP 4.9
1 use utf8;
2 use strict;
3 use warnings;
4  
5 package DR::Tarantool::MsgPack::SyncClient;
6 use base qw(DR::Tarantool::MsgPack::AsyncClient);
7 use AnyEvent;
8 use Carp;
9 use Data::Dumper;
10  
11 sub connect {
12 my ($class, %opts) = @_;
13 my $cv = AE::cv;
14  
15 $opts{raise_error} = 1 unless exists $opts{raise_error};
16  
17 $class->SUPER::connect(%opts, sub { $cv->send(@_) });
18 my ($self) = $cv->recv;
19 croak $self unless ref $self;
20  
21 $self->{raise_error} = $opts{raise_error};
22 return $self;
23 }
24  
25 sub ping {
26 my ($self) = @_;
27 my $cv = AE::cv;
28 $self->SUPER::ping( sub { $cv->send(@_) } );
29 my ($status, $tuple, $code) = $cv->recv;
30 return 1 if $status and $status eq 'ok';
31 return 0;
32 }
33  
34  
35 for my $method (qw(insert replace select update delete call_lua)) {
36 no strict 'refs';
37 *{ __PACKAGE__ . "::$method" } = sub {
38 my ($self, @args) = @_;
39 my $cv = AE::cv;
40 my $m = "SUPER::$method";
41 $self->$m(@args, sub { $cv->send(@_) });
42 my @res = $cv->recv;
43  
44 return $res[1] if $res[0] eq 'ok';
45
46 return undef unless $self->{raise_error};
47 croak sprintf "%s: %s",
48 defined($res[1])? $res[1] : 'unknown',
49 $res[2]
50 ;
51 };
52 }
53  
54  
55 1;