From: Vincent Pit Date: Fri, 24 Sep 2010 18:00:03 +0000 (+0200) Subject: Correctly propagate exceptions from _wizard() X-Git-Tag: v0.44~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=19b708934684141b9dc4b99c8a75165c2d3daabf;p=perl%2Fmodules%2FVariable-Magic.git Correctly propagate exceptions from _wizard() --- diff --git a/lib/Variable/Magic.pm b/lib/Variable/Magic.pm index 5c04932..19badb0 100644 --- a/lib/Variable/Magic.pm +++ b/lib/Variable/Magic.pm @@ -300,18 +300,26 @@ sub wizard { } my %opts = @_; + my @keys = qw/data op_info get set len clear free/; push @keys, 'copy' if MGf_COPY; push @keys, 'dup' if MGf_DUP; push @keys, 'local' if MGf_LOCAL; push @keys, qw/fetch store exists delete copy_key/ if VMG_UVAR; - my $ret = eval { _wizard(map $opts{$_}, @keys) }; - if (my $err = $@) { + + my ($wiz, $err); + { + local $@; + $wiz = eval { _wizard(map $opts{$_}, @keys) }; + $err = $@; + } + if ($err) { $err =~ s/\sat\s+.*?\n//; require Carp; Carp::croak($err); } - return $ret; + + return $wiz; } =head2 C diff --git a/t/18-opinfo.t b/t/18-opinfo.t index c9398cc..6cf8768 100644 --- a/t/18-opinfo.t +++ b/t/18-opinfo.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 17 * (3 + 4) + 5; +use Test::More tests => 17 * (3 + 4) + 5 + 1; use Config qw/%Config/; @@ -106,3 +106,13 @@ for (@tests) { eval { dispell $c, $wiz }; is $@, '', "get dispell with out of bounds op_info doesn't croak"; } + +{ + local $@; + my $wiz = eval { + local $SIG{__WARN__} = sub { die @_ }; + wizard op_info => "hlagh"; + }; + like $@, qr/^Argument "hlagh" isn't numeric in subroutine entry at \Q$0\E/, + 'wizard(op_info => "text") throws numeric warnings'; +}