lib/AnyEvent/Memcached/Hash.pm

filter: Statementstmt 97.3% 36 / 37 Branchbran 62.5% 5 / 8 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 5 totaltotal 76.8% 53 / 69 SCAR 22.2
CC
9
Cov
87%
hashes
6.0
set_buckets
6.0
peers
3.1
CRAP 9.2
« blib/lib/AnyEvent/Memcached/Hash.pm ↑ Summary lib/AnyEvent/Memcached/Hash/WithNext.pm »
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
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
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 ||= {}
l!l
410
MC/DC0%0/1
$peers ||= {}
$peers
Truth table50%1/2
A
A= $peers
Aresult
11
00
26 41 my $peer = $self->{buckets}->peer( $hash );
27 41 ▶ push @{ $peers->{$peer} ||= [] }, $real;
Condition50%1/2
$peers->{$peer} ||= []
l!l
041
MC/DC0%0/1
$peers->{$peer} ||= []
$peers->{$peer}
Truth table50%1/2
A
A= $peers->{$peer}
Aresult
11
00
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
BranchTrueFalseTotal
$self->{"buckets"} or croak("No buckets set during hashes") 0 70 70
34 70 my $keys = shift;
35 70 my $array;
36 70 ▶ if (ref $keys and ref $keys eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $keys and ref $keys eq 'ARRAY') { } 18 52 70
Condition66%2/3
ref $keys and ref $keys eq "ARRAY"
!ll&&!rl&&r
52018
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
ref $keyx ? : 22 60 82
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;
« blib/lib/AnyEvent/Memcached/Hash.pm ↑ Summary lib/AnyEvent/Memcached/Hash/WithNext.pm »