From: Vincent Pit Date: Sat, 9 Aug 2008 10:24:31 +0000 (+0200) Subject: Allow returning from a scalar assignment X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=efc5762598689b6ee22dfc8ad29f4e8a22457c0a;p=perl%2Fmodules%2FSub-Nary.git Allow returning from a scalar assignment --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index b87eaef..2b9b671 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -448,6 +448,15 @@ sub pp_rv2av { $self->inspect($op); } +sub pp_sassign { + my ($self, $op) = @_; + + my $r = ($self->inspect($op->first))[0]; + + my $c = 1 - count $r; + return $r, $c ? { 1 => $c } : undef +} + sub pp_aassign { my ($self, $op) = @_; diff --git a/t/20-return.t b/t/20-return.t index d14a3a5..fe5d21b 100644 --- a/t/20-return.t +++ b/t/20-return.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 67; +use Test::More tests => 68; use Sub::Nary; @@ -27,6 +27,7 @@ my @tests = ( [ sub { do { do { return if $x }, 3 }, 4 }, { 0 => 0.5, 3 => 0.5 } ], [ sub { do { return if $x; 2, 3 }, do { return 1 if $y; 4, 5, 6 } }, { 0 => 0.5, 1 => 0.25, 5 => 0.25 } ], + [ sub { my $x = do { return 2, 3; 4 } }, 2 ], [ sub { return $x }, 1 ], [ sub { return $x, $y }, 2 ],