aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@luxion>2008-12-29 11:41:31 +0000
committerdakkar <dakkar@luxion>2008-12-29 11:41:31 +0000
commitf000aa6898806ef97e9e555625428197fabc2c58 (patch)
tree78b9003d2b0b7d523c3bd40f49188ebeb55d8201
parentforse i feed funzionano… non testato (diff)
downloadWebCoso-f000aa6898806ef97e9e555625428197fabc2c58.tar.gz
WebCoso-f000aa6898806ef97e9e555625428197fabc2c58.tar.bz2
WebCoso-f000aa6898806ef97e9e555625428197fabc2c58.zip
fallback for die-ing writers: use the parser
git-svn-id: svn://luxion/repos/WebCoso/trunk@395 fcb26f47-9200-0410-b104-b98ab5b095f3
-rw-r--r--lib/File/Cache/Parsed.pm18
-rw-r--r--t/fcp-01.t9
2 files changed, 23 insertions, 4 deletions
diff --git a/lib/File/Cache/Parsed.pm b/lib/File/Cache/Parsed.pm
index c67b16b..34f5aed 100644
--- a/lib/File/Cache/Parsed.pm
+++ b/lib/File/Cache/Parsed.pm
@@ -105,12 +105,17 @@ sub stat {
sub put {
my ($self,$filename,$contents)=@_;
+ my $err;
my $ww=first {$filename =~ m{$_->[0]}} @{$self->{writers}};
if ($ww) {
- $self->{cache}{$filename}=$contents;
- return $ww->[1]->($filename,$contents);
+ my $ret=eval {$ww->[1]->($filename,$contents)};
+ unless ($@) {
+ $self->{cache}{$filename}=$contents;
+ return $ret;
+ }
+ $err=$@;
}
- elsif (!ref($contents)) {
+ if (!ref($contents)) {
my $pp=first {$filename =~ m{$_->[0]}} @{$self->{parsers}};
if ($pp) {
$self->{cache}{$filename}=$pp->[1]->($filename,$contents);
@@ -121,7 +126,12 @@ sub put {
return print {file($filename)->openw} $contents;
}
else {
- croak "'$contents' is not a scalar, and no writer defined for the name '$filename'";
+ if ($err) {
+ croak "'$contents' is not a scalar, and the writer for the name '$filename' died with: $err";
+ }
+ else {
+ croak "'$contents' is not a scalar, and no writer defined for the name '$filename'";
+ }
}
}
diff --git a/t/fcp-01.t b/t/fcp-01.t
index 2df0d8c..c54b61f 100644
--- a/t/fcp-01.t
+++ b/t/fcp-01.t
@@ -111,8 +111,17 @@ is($calls{rstuff},1,'called reader');
is($fc->get($wr_file->stringify),
'bad',
'parsed after put');
+
+$fc->add_writer(qr{\.stuff$} => sub { die 'bad call' });
+$wr_contents='buh';
+$fc->put($wr_file->stringify,$wr_contents);
+is($calls{rstuff},2,'called reader on writer exception');
+is($fc->get($wr_file->stringify),
+ 'bad',
+ 'parsed after put with writer exception');
}
+
is($fc->get('nosuchfile'),undef,'return undef on non-existant files');
{