develooper Front page | perl.perl5.porters | Postings from October 2012

sub signatures - status

Thread Next
Peter Martini
October 19, 2012 20:19
sub signatures - status
Message ID:
I'm looking for volunteers to test the branch peter/signatures at

It passes my tests, which is kind of like trying to find out if a person is
sane by asking them, but its at least something and can give an idea of
what I'm aiming for - take a look at t/comp/namedproto.t in that branch.

(I've starred the items below that may be controversial)

sub foo($bar,$baz){} initializes $bar and $baz to the first and second
parameter passed to the function, or undef if there was none.

sub foo($bar,@bar){} does the same, but slurps the second and all remaining
parameters into @bar.

sub foo($bar,%baz){} slurps the second and all remaing parameters into
%baz, in the same manner as my ($bar,%baz) = @_ would

sub foo($bar) : proto($) {} assigns the $ prototype to the sub

B::Deparse has been updated to display the signatures, and the signatures
plus prototype if a sub has both.

*** a literal @_ in a sub with a named parameter will die during compilation

*** a glob that references @_ will die at runtime (I added a 'poison' magic
that will croak on an array access to *main::_)

*** &foo; will die if foo has a sub signature.  I added this since &foo
without parens references the calling subs @_, and I kind of punted on the
question for now.  I suppose treating it as foo(@_) (as long as the calling
sub is allowed to reference @_) is completely legitimate, but it seemed a
very grey area to me...

*** goto into a sub with a signature croaks at runtime

What's left:

Update the documentation

Are there any more B modules I need to update?  -- *Reini*

Test, test, test, code review, code review, code review

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About