perl5i 2.3.0_01 now has basic methods and subroutine signatures with code basically lifted straight from Method::Signatures::Simple. MooseX::Declare got me addicted, now I want them everywhere.
use perl5i::2;
def add($this, $that) {
return $this + $that;
}
method new($class: %args) {
return bless \%args, $class;
}
my $echo = def($arg) { return $arg };
Its alpha for two reasons. First, I don't have time right now to really thoroughly test it, but I really want it.
Second, overriding "sub" is hard.
Its been done but its a bit twitchy. Defining a new keyword is easy(er). So what should that keyword be? I've come up with two that have good arguments. "def" and "func". Both are short. "def" has the benefit of being used by other programming languages a Perl programmer is likely to encounter and not hate (Python, Ruby, Scala, Groovy). "func" is nice because it pretty clearly means "function" whereas "define" is a bit ambiguous.
perl5i currently does both. Only one will survive in version 3 (the other will be deprecated). Before you comment on which is your favorite, try it for a little bit. I found a difference between what I thought I like and what I actually use.