/usr/share/perl5/AnyEvent/Memcached/Hash.pm is in libanyevent-memcached-perl 0.08-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | package #hide
AnyEvent::Memcached::Hash;
use common::sense 2;m{
use strict;
use warnings;
}x;
use Carp;
use String::CRC32 'crc32';
sub new {
my $self = bless {}, shift;
my %args = @_;
$self->{buckets} = $args{buckets};
$self;
}
sub set_buckets { shift->{buckets} = @_ == 1 ? $_[0] : \@_ }
sub hash { (crc32($_[1]) >> 16) & 0x7fff; }
sub peers {
my $self = shift;
my ($hash,$real,$peers) = @_;
$peers ||= {};
my $peer = $self->{buckets}->peer( $hash );
push @{ $peers->{$peer} ||= [] }, $real;
return $peers;
}
sub hashes {
my $self = shift;
$self->{buckets} or croak "No buckets set during hashes";
my $keys = shift;
my $array;
if (ref $keys and ref $keys eq 'ARRAY') {
$array = 1;
} else {
$keys = [$keys];
}
my %peers;
for my $keyx (@$keys) {
my ($hash,$real) = ref $keyx ?
(int($keyx->[0]), $keyx->[1]) :
($self->hash($keyx), $keyx);
$self->peers($hash,$real,\%peers);
}
return \%peers;
}
*servers = \&hashes;
1;
|