From a1be1e72a78d363fdb23ae46e41ee090cd066f24 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 5 Nov 2009 13:21:01 +0100 Subject: use Try::Tiny instead of eval --- Makefile.PL | 1 + lib/File/Cache/Parsed.pm | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Makefile.PL b/Makefile.PL index 5124f7b..6734da3 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -29,5 +29,6 @@ WriteMakefile( 'XML::LibXML::XPathContext' => '0', 'XML::LibXSLT' => '0', 'YAML::Syck' => '0', + 'Try::Tiny' => '0', }, ); diff --git a/lib/File/Cache/Parsed.pm b/lib/File/Cache/Parsed.pm index 280dab7..a8a8e2e 100644 --- a/lib/File/Cache/Parsed.pm +++ b/lib/File/Cache/Parsed.pm @@ -6,6 +6,7 @@ use List::MoreUtils qw(firstidx); use Cwd 'abs_path'; use Path::Class; use Carp; +use Try::Tiny; sub new { my ($class,%opts)=@_; @@ -82,9 +83,7 @@ sub get { return $self->{cache}{$filename} if exists $self->{cache}{$filename}; - my $contents=eval {file($filename)->slurp}; - - return if $@; + my $contents=try {file($filename)->slurp} catch {return}; my $pp=first {$filename =~ m{$_->[0]}} @{$self->{parsers}}; if ($pp) { @@ -110,12 +109,11 @@ sub put { my $err; my $ww=first {$filename =~ m{$_->[0]}} @{$self->{writers}}; if ($ww) { - my $ret=eval {$ww->[1]->($filename,$contents)}; - unless ($@) { + my $ret=try {$ww->[1]->($filename,$contents)} catch {$err=$_}; + unless ($err) { $self->{cache}{$filename}=$contents; return $ret; } - $err=$@; } if (!ref($contents)) { my $pp=first {$filename =~ m{$_->[0]}} @{$self->{parsers}}; -- cgit v1.2.3