File Coverage

lib/Data/Valve/BucketStore/Memcached.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             # $Id: /mirror/coderepos/lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/Memcached.pm 86989 2008-10-01T17:20:18.893695Z daisuke $
2              
3             package Data::Valve::BucketStore::Memcached;
4 1     1   85315 use Moose;
  0            
  0            
5             use Moose::Util::TypeConstraints;
6              
7             extends 'Data::Valve::BucketStore::Object';
8              
9             subtype 'Data::Valve::BucketStore::Object::Memcached'
10             => as 'Object'
11             => where {
12             my $h = $_;
13             foreach my $class qw( Cache::Memcached Cache::Memcached::Fast Cache::Memcached::libmemcached ) {
14             $h->isa($class) and return 1;
15             }
16             return ();
17             }
18             ;
19              
20             coerce 'Data::Valve::BucketStore::Object::Memcached'
21             => from 'HashRef'
22             => via {
23             my $h = $_;
24             my $module = $h->{module} || 'Cache::Memcached';
25             Class::MOP::load_class($module);
26             $module->new($h->{args});
27             }
28             ;
29              
30             has '+store' => (
31             isa => 'Data::Valve::BucketStore::Object::Memcached',
32             coerce => 1,
33             required => 1,
34             default => sub {
35             Class::MOP::load_class('Cache::Memcached');
36             Cache::Memcached->new({
37             servers => [ '127.0.0.1:11211' ]
38             });
39             }
40             );
41              
42             __PACKAGE__->meta->make_immutable;
43              
44             no Moose;
45             no Moose::Util::TypeConstraints;
46              
47             1;
48              
49             __END__
50              
51             =head1 NAME
52              
53             Data::Valve::BucketStore::Memcached - Memcached Backend
54              
55             =head1 DESCRIPTION
56              
57             Data::Valve::BucketStore::Memcached uses Memcached as its storage backend,
58             and allows multiple processes to work together.
59              
60             You need to specify a memcached server in order for t to work:
61              
62             Data::Valve->new(
63             bucket_store => {
64             module => "Memcached",
65             args => {
66             store => {
67             servers => [ '127.0.0.1:11211' ],
68             namespace => ...
69             }
70             }
71             }
72             );
73              
74             This module also provides locking mechanism by means of KeyedMutex.
75             You should specify one at construction time:
76              
77             Data::Valve->new(
78             bucket_store => {
79             module => "Memcached",
80             args => {
81             mutex => {
82             args => {
83             sock => "host:port" # <-- here
84             }
85             }
86             }
87             }
88             );
89              
90             This allows all coordinating processes to share the same mutex, and you will
91             get "correct" throttling information
92              
93             =head1 METHODS
94              
95             =head2 try_push
96              
97             =head2 reset
98              
99             =cut