diff options
-rw-r--r-- | lib/File/Cache/Parsed.pm | 2 | ||||
-rw-r--r-- | t/fcp-01.t | 8 |
2 files changed, 10 insertions, 0 deletions
diff --git a/lib/File/Cache/Parsed.pm b/lib/File/Cache/Parsed.pm index 7792cf1..1546ef1 100644 --- a/lib/File/Cache/Parsed.pm +++ b/lib/File/Cache/Parsed.pm @@ -76,9 +76,11 @@ sub put { my $ww=first {$filename =~ m{$_->[0]}} @{$self->{writers}}; if ($ww) { + $self->{cache}{$filename}=$contents; return $ww->[1]->($filename,$contents); } elsif (!ref($contents)) { + $self->{cache}{$filename}=$contents; return print {file($filename)->openw} $contents; } else { @@ -14,6 +14,7 @@ $fc->add_parser(qr{\.t$} => sub { $calls{t}++;return ['t',@_] }); $fc->add_parser(qr{\.pm$} => sub { $calls{pm}++;return ['pm',@_] }); $fc->add_writer(qr{\.stuff$} => sub { $calls{stuff}++; print {file($_[0])->openw} "gino\n",$_[1]; }); +$fc->add_parser(qr{\.stuff$} => sub { $calls{rstuff}++; return 'bad'}); my $base=file(__FILE__)->parent->parent; @@ -53,9 +54,14 @@ my $wr_contents="something\nor\nother\n"; $fc->put($wr_file->stringify,$wr_contents); is($calls{stuff},1,'called ok 3'); is($wr_file->slurp,"gino\n$wr_contents",'written ok'); +is($fc->get($wr_file->stringify),$wr_contents,'read back from cache'); +ok(! exists $calls{rstuff},'no reader call'); + $fc->put($wr_file->stringify,$wr_contents.2); is($calls{stuff},2,'no caching on write'); is($wr_file->slurp,"gino\n${wr_contents}2",'written ok 2'); +is($fc->get($wr_file->stringify),$wr_contents.2,'cache updated'); +ok(! exists $calls{rstuff},'no reader call'); } { @@ -79,4 +85,6 @@ my $wr_contents={good=>'stuff'}; $fc->put($wr_file->stringify,$wr_contents); is($calls{stuff},3,'called ok 4'); is($wr_file->slurp,"gino\n${wr_contents}",'written ok 3 (ref)'); +is_deeply($fc->get($wr_file->stringify),$wr_contents,'no stringification'); +ok(! exists $calls{rstuff},'no reader call'); } |