Subject: | CHI::Driver->get works incorrectly in some cases |
When `get` method takes data from @_ (this happens, for example, in
`get_multi`), it will return nothing if some eval before this will fail.
Code illustrating this problem is below.
use CHI;
use Data::Dumper;
my $c = CHI->new(driver => 'File', root_dir => '/tmp/test_chi');
$c->set('test' => 'value');
eval { die "Test"; };
print Dumper($c->get_multi_hashref([ 'test' ]));
The reason is that `get` checks for $@ even if it didn't call for `eval
{ $self->fetch }`, as usual. Patch for CHI/Driver.pm is attached, I'm
sure it is clear. Feel free to contact me in case of questions.
Subject: | CHI_Driver_pm.patch |
133,137c133,139
< my $data = $params{data} || eval { $self->fetch($key) };
< if ( my $error = $@ ) {
< $self->_handle_get_error( $error, $key );
< return;
< }
---
> unless ( exists $params{data} ) {
> $params{data} = eval { $self->fetch($key) };
> if ( my $error = $@ ) {
> $self->_handle_get_error( $error, $key );
> return;
> }
> }
140c142
< if ( !defined $data ) {
---
> if ( !defined $params{data} ) {
146c148
< CHI::CacheObject->unpack_from_data( $key, $data, $self->serializer );
---
> CHI::CacheObject->unpack_from_data( $key, $params{data}, $self->serializer );