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

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 79 CC 4 SCAR 15.5
CC
4
Cov
0%
connect
12.0
ping
6.0
BEGIN
2.0
CRAP 4.7
1 use utf8;
2 use strict;
3 use warnings;
4  
5 package DR::Tarantool::MsgPack::CoroClient;
6 use base qw(DR::Tarantool::MsgPack::AsyncClient);
7 use AnyEvent;
8 use Carp;
9 use Data::Dumper;
10 use Coro;
11  
12 sub connect {
13 my ($class, %opts) = @_;
14 my $cv = AE::cv;
15  
16 $opts{raise_error} = 1 unless exists $opts{raise_error};
17  
18 $class->SUPER::connect(%opts, sub { $cv->send(@_) });
19 my ($self) = $cv->recv;
20 croak $self unless ref $self;
21  
22 $self->{raise_error} = $opts{raise_error};
23 return $self;
24 }
25  
26 sub ping {
27 my ($self) = @_;
28 $self->SUPER::ping( Coro::rouse_cb );
29 my ($status, $tuple, $code) = Coro::rouse_wait;
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 $m = "SUPER::$method";
40 $self->$m(@args, Coro::rouse_cb);
41 my @res = Coro::rouse_wait;
42  
43 return $res[1] if $res[0] eq 'ok';
44
45 return undef unless $self->{raise_error};
46 croak sprintf "%s: %s",
47 defined($res[1])? $res[1] : 'unknown',
48 $res[2]
49 ;
50 };
51 }
52  
53  
54 1;