| 1 | package #hide | ||||||||||||||||||||||||||||
| 2 | AnyEvent::Memcached::Hash; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use common::sense 2;m{ | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | use strict; | ||||||||||||||||||||||||||||
| 6 | use warnings; | ||||||||||||||||||||||||||||
| 7 | }x; | ||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 6 | ▶ | use String::CRC32 'crc32'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 2 | ▶ | my $self = bless {}, shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 14 | 2 | $self->{buckets} = $args{buckets}; | |||||||||||||||||||||||||||
| 15 | 2 | $self; | |||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub set_buckets { shift->{buckets} = @_ == 1 ? $_[0] : \@_ } | ||||||||||||||||||||||||||
|
Subroutine
set_buckets: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 60 | ▶ | sub hash { (crc32($_[1]) >> 16) & 0x7fff; } | ||||||||||||||||||||||||||
|
Subroutine
hash: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub peers { | ||||||||||||||||||||||||||||
| 23 | 41 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
peers: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 24 | 41 | my ($hash,$real,$peers) = @_; | |||||||||||||||||||||||||||
| 25 | 41 | ▶ | $peers ||= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$peers ||= {}
MC/DC0%0/1
$peers ||= {}
$peers
Truth table50%1/2
A
A= $peers
| |||||||||||||||||||||||||||||
| 26 | 41 | my $peer = $self->{buckets}->peer( $hash ); | |||||||||||||||||||||||||||
| 27 | 41 | ▶ | push @{ $peers->{$peer} ||= [] }, $real; | ||||||||||||||||||||||||||
|
Condition50%1/2
$peers->{$peer} ||= []
MC/DC0%0/1
$peers->{$peer} ||= []
$peers->{$peer}
Truth table50%1/2
A
A= $peers->{$peer}
| |||||||||||||||||||||||||||||
| 28 | 41 | return $peers; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub hashes { | ||||||||||||||||||||||||||||
| 32 | 70 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
hashes: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 70 | ▶ | $self->{buckets} or croak "No buckets set during hashes"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 70 | my $keys = shift; | |||||||||||||||||||||||||||
| 35 | 70 | my $array; | |||||||||||||||||||||||||||
| 36 | 70 | ▶ | if (ref $keys and ref $keys eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $keys and ref $keys eq "ARRAY"
MC/DC50%1/2
ref $keys and ref $keys eq "ARRAY"
ref $keys
ref $keys eq "ARRAY"
Truth table66%2/3
A and B
A= ref $keysB= ref $keys eq "ARRAY"
| |||||||||||||||||||||||||||||
| 37 | 18 | $array = 1; | |||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | 52 | $keys = [$keys]; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 70 | my %peers; | |||||||||||||||||||||||||||
| 42 | 70 | for my $keyx (@$keys) { | |||||||||||||||||||||||||||
| 43 | 82 | ▶ | my ($hash,$real) = ref $keyx ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | (int($keyx->[0]), $keyx->[1]) : | ||||||||||||||||||||||||||||
| 45 | ($self->hash($keyx), $keyx); | ||||||||||||||||||||||||||||
| 46 | 82 | $self->peers($hash,$real,\%peers); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 70 | return \%peers; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 6 | *servers = \&hashes; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 6 | 1; | |||||||||||||||||||||||||||