X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FSub%2FNary.pm;h=4e244782a0e8650e0f5ca61a422f39b9a853cb6a;hb=d3746e574d46fdfb258a4f3c76fb1534cba0c839;hp=427ee8c7eb7cfe3b021d58ae0887117bd1523bfc;hpb=cab48037c2f684dd60d1860bdc2efa3d10d3e7a3;p=perl%2Fmodules%2FSub-Nary.git diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 427ee8c..4e24478 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -16,13 +16,13 @@ Sub::Nary - Try to count how many elements a subroutine can return in list conte =head1 VERSION -Version 0.01 +Version 0.02 =cut our $VERSION; BEGIN { - $VERSION = '0.01'; + $VERSION = '0.02'; } =head1 SYNOPSIS @@ -102,6 +102,10 @@ returns C<3> or C<4> arguments with probability C<1/2> ; and never returns C<1> argument but returns C<2> with probability C<1/2 * 1/2 = 1/4>, C<3> with probability C<1/2 * 1/2 + 1/2 * 1/2 = 1/2> and C<4> with probability C<1/4> too. +=item * If a core function may return different numbers of scalars, each kind is considered equally possible. + +For example, C returns C<13> elements on success and C<0> on error. The according probability will then be C<< { 0 => 0.5, 13 => 0.5 } >>. + =item * The C state is absorbing in regard of all the other ones. This is just a pedantic way to say that "list + fixed length = list". @@ -416,13 +420,12 @@ sub pp_goto { sub pp_const { my ($self, $op) = @_; - if (class($op) eq 'SVOP' and (my $sv = $self->const_sv($op))) { - my $c = class($sv); - if ($c eq 'AV') { - return $sv->FILL + 1; - } elsif ($c eq 'HV') { - return 2 * $sv->FILL; - } + my $sv = $self->const_sv($op); + my $c = class($sv); + if ($c eq 'AV') { + return $sv->FILL + 1; + } elsif ($c eq 'HV') { + return 2 * $sv->FILL; } return 1; @@ -442,7 +445,17 @@ sub pp_rv2av { return (name($op) eq 'const') ? $self->expect_any($op) : 'list'; } -sub pp_aassign { $_[0]->expect_any($_[1]->first) } +sub pp_aassign { + my ($self, $op) = @_; + + $op = $op->first; + + # Can't assign to return + my ($p, $r) = $self->expect_list($op->sibling); + return $p => 0 if not exists $p->{list}; + + $self->expect_any($op); +} sub pp_leaveloop { $_[0]->expect_return($_[1]->first->sibling) }