Subject: | Support for regexp objects |
Currently it's not possible to store regexp objects using
Cache::Memcached. Here's a sample script:
#!/usr/bin/perl
use Test::More qw(no_plan);
use Cache::Memcached;
diag "Cache::Memcached::VERSION: $Cache::Memcached::VERSION";
my $memc = Cache::Memcached->new({servers => ["127.0.0.1:11211"]});
my $rx = qr{bla};
$memc->set("test.rx", $rx);
my $rx_got = $memc->get("test.rx");
diag $rx_got;
like "bla", $rx;
like "bla", $rx_got;
$memc->delete("test.rx");
__END__
Depending on the perl (or Storable.pm?) version, the result is either an
error when calling ->set:
# Cache::Memcached::VERSION: 1.29
# Storable::VERSION: 2.22
# perl version 5.012000
Can't store REGEXP items at ../../lib/Storable.pm (autosplit into
../../lib/auto/Storable/_freeze.al) line 339, at ../../lib/Storable.pm
(autosplit into ../../lib/auto/Storable/nfreeze.al) line 327
...
or no error when storing in memcached, but the deserialized regexp
object is wrong:
# Cache::Memcached::VERSION: 1.28
# Storable::VERSION: 2.15
# perl version 5.008008
# Regexp=SCALAR(0xbfd1be0)
ok 1
not ok 2
# Failed test in /tmp/mc.pl at line 12.
# 'bla'
# doesn't match 'Regexp=SCALAR(0xbfd1be0)'
1..2
# Looks like you failed 1 test of 2.
At least it would be good to document that storing regexp objects does
not work with Cache::Memcached. Maybe it would be not too hard to
support regexp objects by doing a stringification when serializing and
putting the string into a qr{...} when deserializing.
Regards,
Slaven