lib/AnyEvent/Memcached/Peer.pm

filter: Statementstmt 21.7% 20 / 92 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 6 / 18 Podpod 57.1% 4 / 7 totaltotal 18.9% 30 / 158 SCAR 56.7
CC
21
Cov
15%
__ANON__
56.0
conntrack
42.0
__ANON__
12.0
CRAP 289.3
« blib/lib/AnyEvent/Memcached/Peer.pm ↑ Summary blib/lib/AnyEvent/Memcached/Conn.pm »
1 package #hide
2 AnyEvent::Memcached::Peer;
3  
4 4 ▶use common::sense 2;m{
Subroutine BEGIN: called CC=1 SCAR=0.0
5 use strict;
6 use warnings;
7 }x;
8 4 ▶use base 'AnyEvent::Connection';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use AnyEvent::Connection::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 #use Devel::Leak::Cb;
13 sub DEBUG () { 0 }
14  
15 4 ▶use AnyEvent::Memcached::Conn;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 sub new {
18 0 ▶ my $self = shift->SUPER::new(
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
19 rawcon => 'AnyEvent::Memcached::Conn',
20 reconnect => 1,
21 @_,
22 );
23 0 $self->{waitingcb} = {};
24 0 $self;
25 }
26  
27 sub connect {
28 0 ▶ my $self = shift;
Subroutine connect: not called CC=2 SCAR=17.9
Pod documented
29 0 ▶ $self->{connecting} and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"connecting"} and return 0 0 0
30 0 ▶ $self->{grd}{con} = $self->reg_cb( connected => sub { $self->{failed} = 0; } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 0 ▶ $self->{grd}{cfl} = $self->reg_cb( connfail => sub { $self->{failed} = 1; } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 $self->{grd}{dis} = $self->reg_cb( disconnect => sub {
33 0 ▶ shift;shift;
Subroutine __ANON__: not called CC=7 SCAR=40.3
34 0 ▶ %$self or return;
Branch: 1 branch
BranchTrueFalseTotal
%$self or return 0 0 0
35 0 ▶ warn "Peer $self->{host}:$self->{port} disconnected".(@_ ? ": @_" : '')."\n" if $self->{debug};
Branch: 2 branches
BranchTrueFalseTotal
if $self->{"debug"} 0 0 0
@_ ? : 0 0 0
36 0 ▶ my $e = @_ ? "@_" : "disconnected";
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
37 0 for ( keys %{$self->{waitingcb}} ) {
38 0 ▶ if ($self->{waitingcb}{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"waitingcb"}{$_}) 0 0 0
39 #warn "Cleanup: ",::sub_fullname( $self->{waitingcb}{$_} );
40 0 $self->{waitingcb}{$_}(undef,$e);
41 }
42 0 delete $self->{waitingcb}{$_};
43 }
44 0 } );
45 0 $self->SUPER::connect(@_);
46 0 return;
47 }
48  
49 sub conntrack {
50 0 ▶ my $self = shift;
Subroutine conntrack: not called CC=6 SCAR=37.4
Pod undocumented
51 0 my ($method,$args,$cb) = @_;
52 0 ▶ if($self->{connecting} and $self->{failed}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'connecting'} and $self->{'failed'}) { } 0 0 0
elsif (not $self->{'connected'}) { } 0 0 0
Condition0%0/3
$self->{"connecting"} and $self->{"failed"}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"connecting"} and $self->{"failed"}
$self->{"connecting"} $self->{"failed"}
Truth table0%0/3
A and B
A= $self->{"connecting"}B= $self->{"failed"}
ABresult
0X0
100
111
53 0 warn "Is connecting, have fails => not connected" if DEBUG;
54 0 ▶ $cb and $cb->(undef, "Not connected");
Branch: 1 branch
BranchTrueFalseTotal
$cb and &$cb(undef, "Not connected") 0 0 0
55 0 return;
56 }
57 elsif (!$self->{connected}) {
58 0 my @args = @$args; # copy to avoid rewriting
59 0 warn time()." Not connected, do connect for ".\@args.", ".dumper($args[0]) if DEBUG;
60 0 my ($c,$t);
61 0 ▶ weaken( $self->{waitingcb}{int $cb} = $cb ) if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 0 0
62 0 weaken( $self );
63 # This rely on correct event invocation order of Object::Event.
64 # If this could change, I'll add own queue
65 $c = $self->reg_cb(
66 connected => sub {
67 0 ▶ shift->unreg_me;
Subroutine __ANON__: not called CC=3 SCAR=24.8
68 #$c or return;
69 0 warn "connected cb for ".\@args.", ".dumper($args[0]) if DEBUG;
70 0 undef $c;undef $t;
71 0 ▶ $self or return;
Branch: 1 branch
BranchTrueFalseTotal
$self or return 0 0 0
72 0 ▶ delete $self->{waitingcb}{int $cb} if $cb;
Branch: 1 branch
BranchTrueFalseTotal
if $cb 0 0 0
73 0 return $self->{con}->$method(@args);
74 },
75 0 );
76 $t = AnyEvent->timer(
77 after => $self->{timeout},# + 0.05, # Since there are timers inside connect, we need to delay a bit longer
78 cb => sub {
79 #$t or return;
80 0 ▶ warn time()." timeout $self->{timeout} cb for $args->[0]" if DEBUG;
Subroutine __ANON__: not called CC=3 SCAR=24.8
81 0 undef $c;undef $t;
82 0 ▶ $self or return;
Branch: 1 branch
BranchTrueFalseTotal
$self or return 0 0 0
83 0 ▶ if ($cb){
Branch: 1 branch
BranchTrueFalseTotal
if ($cb) 0 0 0
84 0 $self->{waitingcb}{int $cb};
85 0 $cb->(undef, "Connect timeout");
86 }
87 },
88 0 );
89 0 $self->connect();
90 }
91 else {
92 0 Carp::cluck "How do I get here?";
93 0 return $self->{con}->$method(@$args);
94 }
95 }
96  
97 sub command {
98 0 ▶ my $self = shift;
Subroutine command: not called CC=2 SCAR=17.9
Pod documented
99 0 ▶ if ($self->{connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'connected'}) { } 0 0 0
100 0 return $self->{con}->command( @_ );
101 }
102 else {
103 0 my ($cmd,%args) = @_;
104 0 $self->conntrack( command => \@_, $args{cb} );
105 }
106 }
107  
108 sub request {
109 0 ▶ my $self = shift;
Subroutine request: not called CC=2 SCAR=17.9
Pod documented
110 0 ▶ if ($self->{connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'connected'}) { } 0 0 0
111 0 return $self->{con}->say(@_);
112 }
113 else {
114 # no cb
115 0 $self->conntrack( say => \@_ );
116 }
117 }
118  
119 sub reader {
120 0 ▶ my $self = shift;
Subroutine reader: not called CC=2 SCAR=17.9
Pod undocumented
121 0 ▶ if ($self->{connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'connected'}) { } 0 0 0
122 0 return $self->{con}->reader(@_);
123 }
124 else {
125 0 my %args = @_;
126 0 $self->conntrack( reader => \@_, $args{cb} );
127 }
128
129 }
130  
131 sub want_command {
132 0 ▶ my $self = shift;
Subroutine want_command: not called CC=2 SCAR=17.9
Pod undocumented
133 0 warn "wanting command";
134 0 ▶ if ($self->{connected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'connected'}) { } 0 0 0
135 0 return $self->{con}->want_command(@_);
136 }
137 else {
138 0 my %args = @_;
139 0 $self->conntrack( want_command => \@_ );
140 }
141 }
142  
143 4 1;
« blib/lib/AnyEvent/Memcached/Peer.pm ↑ Summary blib/lib/AnyEvent/Memcached/Conn.pm »