Subject: | allow specifying own freeze/thaw methods |
The attached diff allows shared data usage between different languages like
use Cache::Memcached::libmemcached;
use JSON;
my $json = JSON->new->allow_nonref;
my $mc = Cache::Memcached::libmemcached->new({
servers => [ @servers ],
serialize => sub { $json->encode($_[0]) },
unserialize => sub { $json->decode($_[0]) },
});
Subject: | Cache-Memcached-libmemcached-serialize.diff |
--- Cache-Memcached-libmemcached-0.02011/lib/Cache/Memcached/libmemcached.pm 2011-05-27 01:40:19.000000000 +0200
+++ ../lib/Cache/Memcached/libmemcached.pm 2011-09-20 11:48:14.481168752 +0200
@@ -96,6 +96,9 @@
$self->{compress_enable} =
exists $args->{compress_enable} ? $args->{compress_enable} : 1;
+ $self->{serialize} = $args->{serialize} || \&Storable::nfreeze;
+ $self->{unserialize} = $args->{unserialize} || \&Storable::thaw;
+
# servers
$self->set_servers($args->{servers});
@@ -156,7 +159,7 @@
}
if ($flags & F_STORABLE) {
- $_ = Storable::thaw($_);
+ $_ = $self->{unserialize}->($_);
}
return ();
};
@@ -164,7 +167,7 @@
my $deflate = sub {
# Check if we have a complex structure
if (ref $_) {
- $_ = Storable::nfreeze($_);
+ $_ = $self->{serialize}->($_);
$_[1] |= F_STORABLE;
}
@@ -727,4 +730,4 @@
See http://www.perl.com/perl/misc/Artistic.html
-=cut
\ No newline at end of file
+=cut