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

Re: sub signatures - function to return the signature

Thread Previous
Eirik Berg Hanssen
October 27, 2012 15:08
Re: sub signatures - function to return the signature
Message ID:
On Sat, Oct 27, 2012 at 9:31 PM, Peter Martini <>wrote:

> On Sat, Oct 27, 2012 at 3:06 PM, Eirik Berg Hanssen <
>> wrote:
>>   I still think I prefer C<< no strict 'arity' >>, but the C<<
>> signature($sub) >> object is intriguing.  I think we'll need something like
>> it, and having it, a few utility methods couldn't do much harm ...
> Any ideas for name/location of such a function?  Preference for undef vs
> croak if the sub wasn't defined with a signature?

  I was thinking CORE::signature – why treat it any worse than
CORE::prototype?  ;-)  Though sub::signature could also do, I suppose.

  I had been hoping the "default signature" could also be represented by an
object, so neither croak nor undef.

  There are still a few things we can say about this "default signature".
We _might_ say, in order of most obvious to most speculative:

 * signature($sub)->min # 0
 * signature($sub)->max # MAXINT ... or Inf? ;-)
 * signature($sub)->is_default # true ;-)
 * signature($sub)->slurps # true
 * signature($sub)->params # a list of a single parameter object,
representing the (default, implied, otherwise undeclarable) slurpy @_

  ... and we would not need to check that C<signature($sub)> actually
returns an object, before using it.  C<< (eval { signature($sub) } //
DEFAULT_SIGNATURE) >> would be tedious to write all the time ...


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