| 1 | package AnyEvent::Redis; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use 5.008_001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | our $VERSION = '0.24'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 8 | ▶ | use constant DEBUG => $ENV{ANYEVENT_REDIS_DEBUG}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 8 | ▶ | use AnyEvent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 8 | ▶ | use AnyEvent::Socket; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 8 | ▶ | use AnyEvent::Redis::Protocol; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 8 | ▶ | use Carp qw( croak confess ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 8 | ▶ | use Encode (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 8 | ▶ | use Scalar::Util qw(weaken); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 8 | our $AUTOLOAD; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 19 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $host = delete $args{host} || '127.0.0.1'; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'host'} || '127.0.0.1'
MC/DC0%0/1
delete $args{'host'} || '127.0.0.1'
delete $args{'host'}
Truth table0%0/2
A
A= delete $args{'host'}
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $port = delete $args{port} || 6379; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'port'} || 6379
MC/DC0%0/1
delete $args{'port'} || 6379
delete $args{'port'}
Truth table0%0/2
A
A= delete $args{'port'}
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if (my $encoding = $args{encoding}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | $args{encoding} = Encode::find_encoding($encoding); | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | croak qq{Encoding "$encoding" not found} unless ref $args{encoding}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | bless { | ||||||||||||||||||||||||||||
| 30 | 0 | host => $host, | |||||||||||||||||||||||||||
| 31 | port => $port, | ||||||||||||||||||||||||||||
| 32 | pending_cvs => [], | ||||||||||||||||||||||||||||
| 33 | %args, | ||||||||||||||||||||||||||||
| 34 | }, $class; | ||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub run_cmd { | ||||||||||||||||||||||||||
|
Subroutine
run_cmd: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 0 | my $cmd = shift; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $self->{cmd_cb} or return $self->connect($cmd, @_); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | 0 | $self->{cmd_cb}->($cmd, @_); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 0 | (my $method = $AUTOLOAD) =~ s/.*:://; | |||||||||||||||||||||||||||
| 50 | 0 | $self->run_cmd($method, @_); | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub all_cv { | ||||||||||||||||||||||||||
|
Subroutine
all_cv: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | $self->{all_cv} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $self->{all_cv} ||= AE::cv; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"all_cv"} ||= &AE::cv()
MC/DC0%0/2
$self->{"all_cv"} ||= &AE::cv()
$self->{"all_cv"}
&AE::cv()
Truth table0%0/3
A ||= B
A= $self->{"all_cv"}B= &AE::cv()
| |||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub cleanup { | ||||||||||||||||||||||||||
|
Subroutine
cleanup: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 61 | 0 | delete $self->{cmd_cb}; | |||||||||||||||||||||||||||
| 62 | 0 | delete $self->{sock}; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | $self->{on_error}->(@_) if $self->{on_error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->{on_cleanup}->(@_) if $self->{on_cleanup}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | for (splice(@{$self->{pending_cvs}}), | |||||||||||||||||||||||||||
| 66 | 0 | ▶ | splice(@{$self->{multi_cvs} || []})) | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'multi_cvs'} || []
MC/DC0%0/1
$self->{'multi_cvs'} || []
$self->{'multi_cvs'}
Truth table0%0/2
A
A= $self->{'multi_cvs'}
| |||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | 0 | eval { $_->croak(@_) }; | |||||||||||||||||||||||||||
| 69 | 0 | ▶ | warn "Exception in cleanup callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub connect { | ||||||||||||||||||||||||||
|
Subroutine
connect: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | my $cv; | |||||||||||||||||||||||||||
| 78 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $cv = pop if UNIVERSAL::isa($_[-1], 'AnyEvent::CondVar'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $cv ||= AE::cv; | ||||||||||||||||||||||||||
|
Condition0%0/3
$cv ||= &AE::cv()
MC/DC0%0/2
$cv ||= &AE::cv()
$cv
&AE::cv()
Truth table0%0/3
A ||= B
A= $cvB= &AE::cv()
| |||||||||||||||||||||||||||||
| 81 | 0 | push @{$self->{connect_queue}}, [ $cv, @_ ]; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return $cv if $self->{sock}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | weaken $self; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $self->{sock} = tcp_connect $self->{host}, $self->{port}, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 88 | my $fh = shift | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | my $err = "Can't connect Redis server: $!"; | |||||||||||||||||||||||||||
| 91 | 0 | $self->cleanup($err); | |||||||||||||||||||||||||||
| 92 | 0 | eval { $cv->croak($err) }; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | warn "Exception in connect failure callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | return | ||||||||||||||||||||||||||||
| 95 | 0 | }; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | binmode $fh; # ensure bytes until we decode | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | my $hd = AnyEvent::Handle->new( | ||||||||||||||||||||||||||||
| 100 | fh => $fh, | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | on_error => sub { $_[0]->destroy; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $self->cleanup($_[2]) if $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | on_eof => sub { $_[0]->destroy; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 105 | 0 | $self->cleanup('connection closed'); | |||||||||||||||||||||||||||
| 106 | }, | ||||||||||||||||||||||||||||
| 107 | encoding => $self->{encoding}, | ||||||||||||||||||||||||||||
| 108 | 0 | ); | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $self->{cmd_cb} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=28 SCAR=67.0
| |||||||||||||||||||||||||||||
| 111 | 0 | my $command = lc shift; | |||||||||||||||||||||||||||
| 112 | 0 | my $is_pubsub = $command =~ /^p?(?:un)?subscribe\z/; | |||||||||||||||||||||||||||
| 113 | 0 | my $is_subscribe = $command =~ /^p?subscribe\z/; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # Are we already subscribed to anything? | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | if ($self->{sub} && %{$self->{sub}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sub"} and %{$self->{"sub"};}
MC/DC0%0/2
$self->{"sub"} and %{$self->{"sub"};}
$self->{"sub"}
%{$self->{"sub"};}
Truth table0%0/3
A and B
A= $self->{"sub"}B= %{$self->{"sub"};}
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | croak "Use of non-pubsub command during pubsub session may result in unexpected behaviour" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | unless $is_pubsub; | ||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | # Are we already in a transaction? | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($self->{multi_write}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | croak "Use of pubsub or multi command in transaction is not supported" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_pubsub or $command eq "multi"
MC/DC0%0/2
$is_pubsub or $command eq "multi"
$is_pubsub
$command eq "multi"
Truth table0%0/3
A or B
A= $is_pubsubB= $command eq "multi"
| |||||||||||||||||||||||||||||
| 124 | if $is_pubsub || $command eq 'multi'; | ||||||||||||||||||||||||||||
| 125 | } else { | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | croak "Can't 'exec' a transaction because none is pending" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | if $command eq 'exec'; | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | my ($cv, $cb); | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | ▶ | $cv = pop if ref $_[-1] && UNIVERSAL::isa($_[-1], 'AnyEvent::CondVar'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $_[-1] and UNIVERSAL::isa($_[-1], "AnyEvent::CondVar")
MC/DC0%0/2
ref $_[-1] and UNIVERSAL::isa($_[-1], "AnyEvent::CondVar")
ref $_[-1]
UNIVERSAL::isa($_[-1], "AnyEvent::CondVar")
Truth table0%0/3
A and B
A= ref $_[-1]B= UNIVERSAL::isa($_[-1], "AnyEvent::CondVar")
| |||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $cb = pop if ref $_[-1] eq 'CODE'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | 0 | ▶ | $cv ||= AE::cv; | ||||||||||||||||||||||||||
|
Condition0%0/3
$cv ||= &AE::cv()
MC/DC0%0/2
$cv ||= &AE::cv()
$cv
&AE::cv()
Truth table0%0/3
A ||= B
A= $cvB= &AE::cv()
| |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | croak "Must provide a CODE reference for subscriptions" if $is_subscribe && !$cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_subscribe and not $cb
MC/DC0%0/2
$is_subscribe and not $cb
$is_subscribe
not $cb
Truth table0%0/3
A and not(B)
A= $is_subscribeB= not $cb
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | my $send = join("\r\n", | ||||||||||||||||||||||||||||
| 139 | "*" . (1 + @_), | ||||||||||||||||||||||||||||
| 140 | 0 | map { ('$' . length $_ => $_) } | |||||||||||||||||||||||||||
| 141 | 0 | (uc($command), map { $self->{encoding} && length($_) | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | ? $self->{encoding}->encode($_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"encoding"} and length $_
MC/DC0%0/2
$self->{"encoding"} and length $_
$self->{"encoding"}
length $_
Truth table0%0/3
A and B
A= $self->{"encoding"}B= length $_
| |||||||||||||||||||||||||||||
| 143 | : $_ } @_)) | ||||||||||||||||||||||||||||
| 144 | . "\r\n"; | ||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | warn $send if DEBUG; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # $self is weakened to avoid leaks, hold on to a strong copy | ||||||||||||||||||||||||||||
| 149 | # controlled via a CV. | ||||||||||||||||||||||||||||
| 150 | 0 | my $cmd_cv = AE::cv; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | $cmd_cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 152 | 0 | my $strong_self = $self; | |||||||||||||||||||||||||||
| 153 | 0 | }); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | # pubsub is very different - get it out of the way first | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($is_pubsub) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | $hd->push_write($send); | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $already = $self->{sub} && %{$self->{sub}}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{'sub'} && %{$self->{'sub'};}
MC/DC0%0/2
$self->{'sub'} && %{$self->{'sub'};}
$self->{'sub'}
%{$self->{'sub'};}
Truth table0%0/3
A && B
A= $self->{'sub'}B= %{$self->{'sub'};}
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | ▶ | if ($is_subscribe) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | $self->{sub}->{$_} ||= [$cv, $cb] for @_; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{"sub"}{$_} ||= [$cv, $cb]
MC/DC0%0/1
$self->{"sub"}{$_} ||= [$cv, $cb]
$self->{"sub"}{$_}
Truth table0%0/2
A
A= $self->{"sub"}{$_}
| |||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if (!$already && @_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $already and @_
MC/DC0%0/2
not $already and @_
not $already
@_
Truth table0%0/3
not(A) and B
A= not $alreadyB= @_
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | my $res_cb; $res_cb = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $hd->push_read("AnyEvent::Redis::Protocol" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 170 | 0 | my ($res, $err) = @_; | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if (ref $res) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | my $action = lc $res->[0]; | |||||||||||||||||||||||||||
| 174 | 0 | warn "$action $res->[1]" if DEBUG; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if ($action eq 'message') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 177 | 0 | $self->{sub}->{$res->[1]}[1]->($res->[2], $res->[1]); | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | } elsif ($action eq 'pmessage') { | ||||||||||||||||||||||||||||
| 180 | 0 | $self->{sub}->{$res->[1]}[1]->($res->[3], $res->[2], $res->[1]); | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | ▶ | } elsif ($action eq 'subscribe' || $action eq 'psubscribe') { | |||||||||||||||||||||||||||
|
Condition0%0/3
$action eq "subscribe" or $action eq "psubscribe"
MC/DC0%0/2
$action eq "subscribe" or $action eq "psubscribe"
$action eq "subscribe"
$action eq "psubscribe"
Truth table0%0/3
A or B
A= $action eq "subscribe"B= $action eq "psubscribe"
| |||||||||||||||||||||||||||||
| 183 | 0 | $self->{sub_count} = $res->[2]; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | ▶ | } elsif ($action eq 'unsubscribe' || $action eq 'punsubscribe') { | |||||||||||||||||||||||||||
|
Condition0%0/3
$action eq "unsubscribe" or $action eq "punsubscribe"
MC/DC0%0/2
$action eq "unsubscribe" or $action eq "punsubscribe"
$action eq "unsubscribe"
$action eq "punsubscribe"
Truth table0%0/3
A or B
A= $action eq "unsubscribe"B= $action eq "punsubscribe"
| |||||||||||||||||||||||||||||
| 186 | 0 | $self->{sub_count} = $res->[2]; | |||||||||||||||||||||||||||
| 187 | 0 | eval { $self->{sub}->{$res->[1]}[0]->send }; | |||||||||||||||||||||||||||
| 188 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | 0 | delete $self->{sub}->{$res->[1]}; | |||||||||||||||||||||||||||
| 190 | 0 | $self->all_cv->end; | |||||||||||||||||||||||||||
| 191 | 0 | $cmd_cv->send; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | } else { | ||||||||||||||||||||||||||||
| 194 | 0 | warn "Unknown pubsub action: $action"; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ($self->{sub_count} || %{$self->{sub}}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"sub_count"} or %{$self->{"sub"};}
MC/DC0%0/2
$self->{"sub_count"} or %{$self->{"sub"};}
$self->{"sub_count"}
%{$self->{"sub"};}
Truth table0%0/3
A or B
A= $self->{"sub_count"}B= %{$self->{"sub"};}
| |||||||||||||||||||||||||||||
| 199 | # Carry on reading while we are subscribed | ||||||||||||||||||||||||||||
| 200 | 0 | $res_cb->(); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | }); | |||||||||||||||||||||||||||
| 203 | 0 | }; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | $res_cb->(); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | return $cv; | |||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | # non-pubsub from here on out | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $cv->cb(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 214 | 0 | my $cv = shift; | |||||||||||||||||||||||||||
| 215 | 0 | local $@; | |||||||||||||||||||||||||||
| 216 | 0 | eval { | |||||||||||||||||||||||||||
| 217 | 0 | my $res = $cv->recv; | |||||||||||||||||||||||||||
| 218 | 0 | $cb->($res); | |||||||||||||||||||||||||||
| 219 | }; | ||||||||||||||||||||||||||||
| 220 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | ▶ | ($self->{on_error} || sub { die @_ })->(my $err = $@); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$self->{'on_error'} || sub {
die @_;
}
MC/DC0%0/2
$self->{'on_error'} || sub {
die @_;
}
$self->{'on_error'}
sub {
die @_;
}
Truth table0%0/3
A || B
A= $self->{'on_error'}B= sub {
die @_;
}
| |||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | }) if $cb; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 0 | $self->all_cv->begin; | |||||||||||||||||||||||||||
| 226 | 0 | push @{$self->{pending_cvs}}, $cv; | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | $hd->push_write($send); | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | ▶ | if ($command eq 'exec') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | # at end of transaction, expect bulk reply possibly including errors | ||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $hd->push_read("AnyEvent::Redis::Protocol" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=10 SCAR=47.0
| |||||||||||||||||||||||||||||
| 234 | 0 | my ($res, $err) = @_; | |||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | $self->_expect($cv); | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | my @mcvs = splice @{$self->{multi_cvs}}; | |||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 0 | ▶ | if ($err || ref($res) ne 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$err or ref $res ne "ARRAY"
MC/DC0%0/2
$err or ref $res ne "ARRAY"
$err
ref $res ne "ARRAY"
Truth table0%0/3
A or B
A= $errB= ref $res ne "ARRAY"
| |||||||||||||||||||||||||||||
| 241 | 0 | for ($cv, @mcvs) { | |||||||||||||||||||||||||||
| 242 | 0 | eval { $_->croak($res, 1) }; | |||||||||||||||||||||||||||
| 243 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | } else { | ||||||||||||||||||||||||||||
| 246 | 0 | for my $i (0 .. $#mcvs) { | |||||||||||||||||||||||||||
| 247 | 0 | my $r = $res->[$i]; | |||||||||||||||||||||||||||
| 248 | 0 | eval { | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | ref($r) && UNIVERSAL::isa($r, 'AnyEvent::Redis::Error') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $r and UNIVERSAL::isa($r, "AnyEvent::Redis::Error")
MC/DC0%0/2
ref $r and UNIVERSAL::isa($r, "AnyEvent::Redis::Error")
ref $r
UNIVERSAL::isa($r, "AnyEvent::Redis::Error")
Truth table0%0/3
A and B
A= ref $rB= UNIVERSAL::isa($r, "AnyEvent::Redis::Error")
| |||||||||||||||||||||||||||||
| 250 | ? $mcvs[$i]->croak($$r) | ||||||||||||||||||||||||||||
| 251 | : $mcvs[$i]->send($r); | ||||||||||||||||||||||||||||
| 252 | }; | ||||||||||||||||||||||||||||
| 253 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | 0 | eval { $cv->send($res) }; | |||||||||||||||||||||||||||
| 256 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 0 | $self->all_cv->end; | |||||||||||||||||||||||||||
| 260 | 0 | $cmd_cv->send; | |||||||||||||||||||||||||||
| 261 | 0 | }); | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | delete $self->{multi_write}; | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | } elsif ($self->{multi_write}) { | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | # in transaction, expect only "QUEUED" | ||||||||||||||||||||||||||||
| 268 | 0 | ▶ | $hd->push_read("AnyEvent::Redis::Protocol" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 269 | 0 | my ($res, $err) = @_; | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | $self->_expect($cv); | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | if (!$err && $res eq 'QUEUED') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $err and $res eq "QUEUED"
MC/DC0%0/2
not $err and $res eq "QUEUED"
not $err
$res eq "QUEUED"
Truth table0%0/3
not(A) and B
A= not $errB= $res eq "QUEUED"
| |||||||||||||||||||||||||||||
| 274 | 0 | push @{$self->{multi_cvs}}, $cv; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | else { | ||||||||||||||||||||||||||||
| 277 | 0 | eval { $cv->croak($res) }; | |||||||||||||||||||||||||||
| 278 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | $self->all_cv->end; | |||||||||||||||||||||||||||
| 282 | 0 | $cmd_cv->send; | |||||||||||||||||||||||||||
| 283 | 0 | }); | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | $hd->push_read("AnyEvent::Redis::Protocol" => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 288 | 0 | my ($res, $err) = @_; | |||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | $self->_expect($cv); | |||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | 0 | ▶ | if ($command eq 'info') { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 293 | 0 | $res = { map { split /:/, $_, 2 } grep !/^#/, split /\r\n/, $res }; | |||||||||||||||||||||||||||
| 294 | ▶ | } elsif ($command eq 'keys' && !ref $res) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$command eq "keys" and not ref $res
MC/DC0%0/2
$command eq "keys" and not ref $res
$command eq "keys"
not ref $res
Truth table0%0/3
A and not(B)
A= $command eq "keys"B= not ref $res
| |||||||||||||||||||||||||||||
| 295 | # Older versions of Redis (1.2) need this | ||||||||||||||||||||||||||||
| 296 | 0 | $res = [split / /, $res]; | |||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | ▶ | eval { $err ? $cv->croak($res) : $cv->send($res) }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | 0 | ▶ | warn "Exception in callback (ignored): $@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 0 | $self->all_cv->end; | |||||||||||||||||||||||||||
| 303 | 0 | $cmd_cv->send; | |||||||||||||||||||||||||||
| 304 | 0 | }); | |||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | $self->{multi_write} = 1 if $command eq 'multi'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | return $cv; | |||||||||||||||||||||||||||
| 311 | 0 | }; | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | ▶ | my $queue = delete $self->{connect_queue} || []; | ||||||||||||||||||||||||||
|
Condition0%0/2
delete $self->{'connect_queue'} || []
MC/DC0%0/1
delete $self->{'connect_queue'} || []
delete $self->{'connect_queue'}
Truth table0%0/2
A
A= delete $self->{'connect_queue'}
| |||||||||||||||||||||||||||||
| 314 | 0 | for my $command (@$queue) { | |||||||||||||||||||||||||||
| 315 | 0 | my($cv, @args) = @$command; | |||||||||||||||||||||||||||
| 316 | 0 | $self->{cmd_cb}->(@args, $cv); | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 0 | }; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | 0 | return $cv; | |||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | sub _expect { | ||||||||||||||||||||||||||
|
Subroutine
_expect: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 325 | 0 | my ($self, $cv) = @_; | |||||||||||||||||||||||||||
| 326 | 0 | ▶ | my $p = shift @{$self->{pending_cvs} || []}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->{'pending_cvs'} || []
MC/DC0%0/1
$self->{'pending_cvs'} || []
$self->{'pending_cvs'}
Truth table0%0/2
A
A= $self->{'pending_cvs'}
| |||||||||||||||||||||||||||||
| 327 | 0 | ▶ | $p && $p == $cv or confess "BUG: mismatched CVs"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$p and $p == $cv
MC/DC0%0/2
$p and $p == $cv
$p
$p == $cv
Truth table0%0/3
A and B
A= $pB= $p == $cv
| |||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | 8 | 1; | |||||||||||||||||||||||||||
| 331 | __END__ | ||||||||||||||||||||||||||||