Want, wrapper subs and context preservation (Re: RFC 21 (v1) Replace C<wantarray> with a generic C<wa)

[email protected] ("William Campbell") Sun, 6 Aug 2000 18:41:27 +0100
Newsgroups perl.perl6.language.subs
Message-ID <000501bfffcd$8f9a5ce0$7617989e@stand>
Will the proposed new want operator make writing wrapper 
subroutines which recreate their own context for the 
subroutine they are wrapping harder?

For example how would the following perl 5 subroutine
be rewritten under perl 6 with the want operator?

sub wrapper {
  my (@ret,$ret);
 
  lock_resource();

  if (wantarray) {
    @ret = &wrapped;
  } elsif (defined wantarray) {
    $ret = &wrapped;
  } else {
    &wrapped;
  }
 
  unlock_resource();

  if (wantarray) {
    return @ret;
  } elsif (defined wantarray) {
    return $ret;
  } else {
    return;
  }
}

Presumably wrapped() currently does one of 3 different 
things according to the value of wantarray but might be
enhanced to do one of up to 21 different things according 
to the value of want.

William