| 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 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use Moose::Util::TypeConstraints; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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__ | ||