| 1 | package CHI::Driver::Memcached::Test::Driver; | ||
| 2 | $CHI::Driver::Memcached::Test::Driver::VERSION = '0.15'; | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use Moose; | ||
| 6 | use CHI::t::Driver; | ||
| 7 | use CHI::Driver::Memcached::t::CHIDriverTests; | ||
| 8 | use base qw(CHI::Driver::Memcached); | ||
| 9 | |||
| 10 | __PACKAGE__->meta->make_immutable; | ||
| 11 | |||
| 12 | # Reverse declare_unsupported_methods | ||
| 13 | # | ||
| 14 | foreach my $method (qw(dump_as_hash is_empty purge)) { | ||
| 15 | no strict 'refs'; | ||
| 16 | *{ __PACKAGE__ . "::$method" } = sub { | ||
| 17 | my $self = shift; | ||
| 18 | my $full_method = "CHI::Driver::$method"; | ||
| 19 | return $self->$full_method(@_); | ||
| 20 | }; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub all_test_keys { | ||
| 24 | my ($standard_keys) = | ||
| 25 | CHI::Driver::Memcached::t::CHIDriverTests->set_standard_keys_and_values(); | ||
| 26 | my $all_test_keys = [ | ||
| 27 | values(%$standard_keys), | ||
| 28 | CHI::Driver::Memcached::t::CHIDriverTests->extra_test_keys() | ||
| 29 | ]; | ||
| 30 | return $all_test_keys; | ||
| 31 | } | ||
| 32 | |||
| 33 | # Memcached doesn't support get_keys. For testing purposes, define get_keys | ||
| 34 | # and clear by checking for all keys used during testing. Note, some keys | ||
| 35 | # are changed in CHIDriverTests::set_standard_keys_and_values. | ||
| 36 | # | ||
| 37 | sub get_keys { | ||
| 38 | my $self = shift; | ||
| 39 | |||
| 40 | my $all_test_keys = $self->all_test_keys; | ||
| 41 | my $values = $self->get_multi_hashref($all_test_keys); | ||
| 42 | my @defined_keys = grep { defined $values->{$_} } keys(%$values); | ||
| 43 | return @defined_keys; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub clear { | ||
| 47 | my $self = shift; | ||
| 48 | |||
| 49 | my $all_test_keys = $self->all_test_keys; | ||
| 50 | foreach my $key (@$all_test_keys) { | ||
| 51 | $self->remove($key); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; |