From: Vincent Pit Date: Fri, 8 Aug 2008 22:23:56 +0000 (+0200) Subject: Simplify pp_entersub argument list logic and improve coverage with a test X-Git-Tag: v0.03~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=5f152e1748a0f22036762abc24f5b92859951910;p=perl%2Fmodules%2FSub-Nary.git Simplify pp_entersub argument list logic and improve coverage with a test --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 838fab0..ee5fb64 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -353,14 +353,9 @@ sub pp_entersub { my $r; my $c = 1; for (; not null $op->sibling; $op = $op->sibling) { - my $n = name($op); - next if $n eq 'nextstate'; my ($rc, $lc) = $self->inspect($op); - $r = add $r, scale $c, $rc if defined $rc; - if (zero $lc) { - $c = 1 - count $r; - return $r, $c ? { 0 => $c } : undef - } + return $rc, $lc if defined $rc and not defined $lc; + $r = add $r, scale $c, $rc; $c *= count $lc; } diff --git a/t/22-call.t b/t/22-call.t index 6aa7863..f6fe4e6 100644 --- a/t/22-call.t +++ b/t/22-call.t @@ -3,12 +3,14 @@ use strict; use warnings; -use Test::More tests => 42; +use Test::More tests => 43; use Sub::Nary; my $sn = Sub::Nary->new(); +my $x; + sub CORE::GLOBAL::reset { return 1, 2, 3 } @@ -38,8 +40,9 @@ my @tests = ( [ sub { do { one, do { two } } }, 3 ], [ sub { do { lots, do { one } } }, 'list' ], - [ sub { 1, return two, do { 4 } }, 3 ], - [ sub { two 1, return 2 }, 1 ], + [ sub { 1, return two, do { 4 } }, 3 ], + [ sub { two 1, return 2 }, 1 ], + [ sub { two 1, do { return 5 if $x; 3 } }, { 1 => 0.5, 2 => 0.5 } ], [ sub { 1, one(), 2 }, 3 ], [ sub { 1, one(), @_ }, 'list' ],