in reply to Re: How to protect Redis calls with eval ?
in thread How to protect Redis calls with eval ?

Worked fine with wantarray(). Thanks for the hint. Here is the final code :

## Wonderful catch-all sub AUTOLOAD { # Input variables my ($instance_ref) = shift(@_) ; # Internal vars $tries = 0 ; my $wantarray = wantarray() ; # Determine initially called sub my $command = $AUTOLOAD ; # Format it to call corresponding method on Redis package $command =~ s/.*:// ; $command = 'SUPER::' . $command ; TRY:while($tries < $maxtries) { # Array $errorcode = eval {@result_array = $instance_ref->$command(@_) +} if(defined($wantarray) && $wantarray) ; # Scalar $errorcode = eval {$result_scalar = $instance_ref->$command(@_ +)} if(defined($wantarray) && !$wantarray) ; # Scalar $errorcode = eval {$instance_ref->$command(@_)} if(!defined($wantarray)) ; # Did it went well ? if(!defined($errorcode) && $@ ne '') { # No - log something ? warn("Could not send command $command to Redis server, try + $tries on $maxtries, reason : $@") ; # Update count $tries++ ; # Wait a little bit sleep(1) ; # Go back to work next TRY; } # Otherwise that's cool last TRY; } # Return data return @result_array if(defined($wantarray) && $wantarray) ; return $result_scalar if(defined($wantarray) && !$wantarray) ; return if(!defined($wantarray)) ; }

Thanks for your help.