From: Graham Knop Date: Sun, 28 Jun 2015 20:47:05 +0000 (-0400) Subject: protect against empty string in PV X-Git-Tag: v1.003003~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FEval-WithLexicals.git;a=commitdiff_plain;h=a214c345e2de0ddd1e2ab205d942e2b1d7bb47b1;hp=fb37a6a203f433bb192b039c179b83358330fba7 protect against empty string in PV In perl 5.22, PV can return an empty string as well as undefined, so we need to test the length before using it as a variable name. --- diff --git a/Changes b/Changes index c56d0fb..bdf41f2 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Eval-WithLexicals + - fix failures on threaded perl 5.22 (RT#102841) + 1.003002 - 2014-12-23 - fix test failures on perl 5.21.7 (RT#101086; thanks, Father Chrysostomos!) diff --git a/lib/Eval/WithLexicals.pm b/lib/Eval/WithLexicals.pm index 79fba31..0f9c2fa 100644 --- a/lib/Eval/WithLexicals.pm +++ b/lib/Eval/WithLexicals.pm @@ -131,7 +131,7 @@ sub _eval_do { sub capture_list { my $pad_capture = \&Eval::WithLexicals::Cage::pad_capture; - my @names = grep defined && $_ ne '&', map $_->PV, grep $_->can('PV'), + my @names = grep defined && length && $_ ne '&', map $_->PV, grep $_->can('PV'), svref_2object($pad_capture)->OUTSIDE->PADLIST->ARRAYelt(0)->ARRAY; $Eval::WithLexicals::current_code .= '+{ '.join(', ', map "'$_' => \\$_", @names).' };' diff --git a/t/hints.t b/t/hints.t index 5ce67d8..15db971 100644 --- a/t/hints.t +++ b/t/hints.t @@ -54,4 +54,10 @@ $eval->eval(q{ use hint_hash_pragma 'param' }), is $eval->hints->{q{%^H}}->{hint_hash_pragma}, 'param', "Lexical pragma captured"; +$eval->eval('my $x = 1'); +is_deeply( + $eval->lexicals->{'$x'}, \1, + 'Lexical captured when preserving hints', +); + done_testing;