lib/AnyEvent/Memcached/Hash/WithNext.pm

filter: Statementstmt 100% 21 / 21 Branchbran n/a Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 91.4% 32 / 35 SCAR 13.9
CC
4
Cov
96%
peers
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 4.0
« lib/AnyEvent/Memcached/Hash.pm ↑ Summary blib/lib/AnyEvent/Memcached/Hash/WithNext.pm »
1 package AnyEvent::Memcached::Hash::WithNext;
2  
3 =head1 NAME
4  
5 AnyEvent::Memcached::Hash::WithNext - Hashing algorythm for AE::Memcached
6  
7 =head1 SYNOPSIS
8  
9 my $memd = AnyEvent::Memcached->new(
10 servers => [ "10.0.0.15:10001", "10.0.0.15:10002", "10.0.0.15:10003" ],
11 # ...
12 hasher => 'AnyEvent::Memcached::Hash::WithNext',
13 );
14 $memd->set(key => "val", ...) # will put key on 2 servers
15  
16 =head1 DESCRIPTION
17  
18 Uses the same hashing, as default, but always put key to server, next after choosen. Result is twice-replicated data. Useful for usage with memcachdb
19  
20 =cut
21  
22 1 ▶use common::sense 2;m{
Subroutine BEGIN: called CC=1 SCAR=0.0
23 use strict;
24 use warnings;
25 }x;
26 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use base 'AnyEvent::Memcached::Hash';
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub peers {
30 41 ▶ my $self = shift;
Subroutine peers: called CC=4 SCAR=13.9
Pod undocumented
31 41 my ($hash,$real,$peers) = @_;
32 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
33 41 my $peer = $self->{buckets}->peer( $hash );
34 41 my $next = $self->{buckets}->next( $peer );
35 41 ▶ push @{ $peers->{$peer} ||= [] }, $real;
Condition100%2/2
$peers->{$peer} ||= []
l!l
635
MC/DC100%1/1
$peers->{$peer} ||= []
$peers->{$peer}
Truth table100%2/2
A
A= $peers->{$peer}
Aresult
11
00
36 41 ▶ push @{ $peers->{$next} ||= [] }, $real;
Condition100%2/2
$peers->{$next} ||= []
l!l
239
MC/DC100%1/1
$peers->{$next} ||= []
$peers->{$next}
Truth table100%2/2
A
A= $peers->{$next}
Aresult
11
00
37 41 return $peers;
38 }
39  
40 =head1 AUTHOR
41  
42 Mons Anderson, C<< <mons at cpan.org> >>
43  
44 =cut
45  
46 1 1;
« lib/AnyEvent/Memcached/Hash.pm ↑ Summary blib/lib/AnyEvent/Memcached/Hash/WithNext.pm »