From: Matt S Trout Date: Thu, 17 May 2012 23:26:14 +0000 (+0000) Subject: context sensitivity X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fdg;p=p5sagit%2FEval-WithLexicals.git context sensitivity --- diff --git a/Changes b/Changes index de1b23b..c689b37 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Obey scalar versus list context for ->eval return - HintPersistence plugin to persist compile time hints (DGL) - Support plugins (DGL) - Make prelude configurable, so strictures can be optional (DGL) diff --git a/lib/Eval/WithLexicals.pm b/lib/Eval/WithLexicals.pm index 752de55..cb6f33d 100644 --- a/lib/Eval/WithLexicals.pm +++ b/lib/Eval/WithLexicals.pm @@ -93,7 +93,7 @@ sub _run { %{$self->lexicals}, %{$self->_grab_captures}, }); - @ret; + return $self->context eq 'list' ? @ret : $ret[0]; } sub _grab_captures { diff --git a/t/simple.t b/t/simple.t index e8157ba..667a89d 100644 --- a/t/simple.t +++ b/t/simple.t @@ -47,4 +47,8 @@ is_deeply( 'Sub created ok' ); +$eval->context('scalar'); + +is($eval->eval('$y->(2)'), '3', 'Scalar eval ok'); + done_testing;