gitweb/lib - Add support for setting error handler in cache
commitdd8d6e92f106d298ee8e59d404f1b111b67f6e59
authorJakub Narebski <jnareb@gmail.com>
Sun, 5 Dec 2010 23:01:10 +0000 (6 00:01 +0100)
committerJakub Narebski <jnareb@gmail.com>
Sun, 5 Dec 2010 23:01:10 +0000 (6 00:01 +0100)
treead6b35c88a01ffef803985ed56c3eae44aa48e56
parentfc07456a656eb7d685d78d8e8f7b5e50007d1970
gitweb/lib - Add support for setting error handler in cache

GitwebCache::SimpleFileCache and GitwebCache::FileCacheWithLocking
acquired support for 'on_error'/'error_handler' parameter, which
accepts the same values as 'on_get_error' and 'on_set_error' option in
CHI, with exception of support for "log".  The default is "die" (as it
was before), though it now uses "croak" from Carp, rather than plain
"die".

Added basic test for 'on_error' in t9503: setting it to error handler
that dies, and setting it to 'ignore'.

The way error handler coderef is invoked is slightly different from
the way CHI does it: the error handler doesn't pass key and raw error
message as subsequent parameters.

Because '$self->_handle_error($msg)' is used in place of 'die $msg',
read_file and write_fh subroutines had to be converted to methods, to
have access to $self.  Alternate solution would be to catch errors
using "eval BLOCK" in ->get() and ->set() etc., like in CHI::Driver.

Note that external subroutines that croak()/die() on error (like
'mkpath' or 'tempfile') are now wrapped in eval block (this would be
not necessary if alternate solution described above was used).

While at it refactor ensuring that directory exists (for opening file
for writing, possibly creating it) into ->ensure_path($dir) method.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
gitweb/lib/GitwebCache/FileCacheWithLocking.pm
gitweb/lib/GitwebCache/SimpleFileCache.pm
t/t9503/test_cache_interface.pl