| 1 | package #hide | ||||||||||||||||||||||
| 2 | AnyEvent::Memcached::Conn; | ||||||||||||||||||||||
| 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::Raw'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | 4 | ▶ | use AnyEvent::Memcached; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | 4 | ▶ | use AnyEvent::Connection::Util; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | 4 | our $NL = "\015\012"; | |||||||||||||||||||||
| 13 | 4 | our $QRNL = qr<\015?\012>; | |||||||||||||||||||||
| 14 | 4 | our $VERSION = $AnyEvent::Memcached::VERSION; | |||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | sub reader { | ||||||||||||||||||||||
| 17 | 0 | ▶ | my ($self,%args) = @_; | ||||||||||||||||||||
|
Subroutine
reader: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||
| 18 | 0 | ▶ | $args{cb} or return $self->event( error => "no cb for command at @{[ (caller)[1,2] ]}" ); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 19 | 0 | ▶ | $self->{h} or return $args{cb}->(undef,"Not connected"); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 20 | 0 | ▶ | my $result = $args{res} || {}; | ||||||||||||||||||||
|
Condition0%0/2
$args{'res'} || {}
MC/DC0%0/1
$args{'res'} || {}
$args{'res'}
Truth table0%0/2
A
A= $args{'res'}
| |||||||||||||||||||||||
| 21 | 0 | ▶ | my $ar = ref $result eq 'ARRAY' ? 1 : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 22 | 0 | ▶ | my $cut = exists $args{namespace} ? length $args{namespace} : 0; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 23 | 0 | my $reader;$reader = sub { | |||||||||||||||||||||
| 24 | 0 | ▶ | shift; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||
| 25 | 0 | ▶ | defined( local $_ = shift ) or return $args{cb}(undef,@_); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 26 | 0 | ▶ | warn "<<$args{id} $_" if $self->{debug}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 27 | 0 | ▶ | if ($_ eq "END") { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 28 | 0 | undef $reader; | |||||||||||||||||||||
| 29 | 0 | $args{cb}( $result ); | |||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||
| 31 | elsif (substr($_,0,5) eq 'ERROR') { | ||||||||||||||||||||||
| 32 | 0 | undef $reader; | |||||||||||||||||||||
| 33 | 0 | $args{cb}( undef, $_ ); | |||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | elsif (!length) { | ||||||||||||||||||||||
| 36 | 0 | warn "Skip empty line"; | |||||||||||||||||||||
| 37 | 0 | $self->{h}->unshift_read( line => $reader); | |||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||
| 39 | elsif( /^VALUE (\S+) (\d+) (\d+)(?:| (.+))$/ ) { | ||||||||||||||||||||||
| 40 | 0 | my ($key,$flags,$len,$cas) = ($1,$2,$3,$4); | |||||||||||||||||||||
| 41 | #warn "have to read $1 $2 $3 $4"; | ||||||||||||||||||||||
| 42 | $self->recv( $3+2 => cb => sub { | ||||||||||||||||||||||
| 43 | #shift; | ||||||||||||||||||||||
| 44 | 0 | ▶ | my $data = shift; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||
| 45 | 0 | substr($data,$len) = ''; # trim out data outside length | |||||||||||||||||||||
| 46 | #$data = substr($data,0,length($data)-2); | ||||||||||||||||||||||
| 47 | 0 | ▶ | $key = substr($key, $cut) if substr($key, 0, $cut) eq $args{namespace}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 48 | 0 | ▶ | warn "+ received data $key: $data" if $self->{debug}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 49 | 0 | ▶ | my $v = { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 50 | data => $data, | ||||||||||||||||||||||
| 51 | flags => $flags, | ||||||||||||||||||||||
| 52 | defined $cas ? (cas => $cas) : (), | ||||||||||||||||||||||
| 53 | }; | ||||||||||||||||||||||
| 54 | 0 | ▶ | if ($ar) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 55 | 0 | push @$result, $key, $v; | |||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||
| 57 | 0 | $result->{$key} = $v;#{ data => $data, $cas ? (cas => $cas) : () }; | |||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||
| 59 | |||||||||||||||||||||||
| 60 | 0 | $self->{h}->unshift_read( line => $reader); | |||||||||||||||||||||
| 61 | 0 | }); | |||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||
| 63 | else { | ||||||||||||||||||||||
| 64 | 0 | die "Wrong data received: ".dumper($_)."($!)"; | |||||||||||||||||||||
| 65 | #$args{cb}(undef,$_); | ||||||||||||||||||||||
| 66 | #$self->handle_errors($_); | ||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | 0 | }; | |||||||||||||||||||||
| 69 | 0 | $self->{h}->push_read( line => $reader ); | |||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||
| 71 | |||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 4 | 1; | |||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | 4 | 1; | |||||||||||||||||||||