From: Karen Etheridge Date: Tue, 5 Feb 2013 17:41:39 +0000 (-0800) Subject: use Try::Tiny instead of eval X-Git-Tag: v0.53~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Getopt.git;a=commitdiff_plain;h=5c03810158fc8d7fd7a008401db0bab8b14983af use Try::Tiny instead of eval --- diff --git a/lib/MooseX/Getopt/Basic.pm b/lib/MooseX/Getopt/Basic.pm index 240f683..0a3a255 100644 --- a/lib/MooseX/Getopt/Basic.pm +++ b/lib/MooseX/Getopt/Basic.pm @@ -7,6 +7,7 @@ use MooseX::Getopt::OptionTypeMap; use MooseX::Getopt::Meta::Attribute; use MooseX::Getopt::Meta::Attribute::NoGetopt; use MooseX::Getopt::ProcessedArgv; +use Try::Tiny; use Carp (); use Getopt::Long 2.37 (); @@ -46,12 +47,12 @@ sub process_argv { $configfile = &$configfile($class); } if (defined $configfile) { - $config_from_file = eval { + $config_from_file = try { $class->get_config_from_file($configfile); - }; - if ($@) { - die $@ unless $@ =~ /Specified configfile '\Q$configfile\E' does not exist/; } + catch { + die $_ unless /Specified configfile '\Q$configfile\E' does not exist/; + }; } } else { @@ -112,14 +113,16 @@ sub _parse_argv { my $argv_copy = [ @ARGV ]; my @warnings; - my ( $parsed_options, $usage ) = eval { + my ( $parsed_options, $usage ) = try { local $SIG{__WARN__} = sub { push @warnings, @_ }; return $class->_getopt_get_options(\%params, $opt_spec); + } + catch { + $class->_getopt_spec_exception(\@warnings, $_); }; $class->_getopt_spec_warnings(@warnings) if @warnings; - $class->_getopt_spec_exception(\@warnings, $@) if $@; # Get a copy of the Getopt::Long-mangled @ARGV my $argv_mangled = [ @ARGV ];