[Perl5-syntax] signature syntax for method return values

Ash Berlin ash_cpan at firemirror.com
Wed Feb 25 20:00:59 GMT 2009


On 25 Feb 2009, at 19:34, Florian Ragwitz wrote:

> I wanted to add return value type constraints to
> MooseX::Method::Signatures for a while now, but I have no idea what  
> the
> signature syntax for that should look like.
>
> Any ideas?
>
> I was thinking something like
>
>  method foo (Str $a, Int $b $some_seperator HashRef) { ... }
>
> or
>
>  method foo (Str $a, Int $b) $some_seperator HashRef { ... }

of those two I prefer the latter.

>
>
> where $some_seperator might be something like '-->', '->', '→' or
> 'Returns'.


'returns' has the advantage of being nice and explicit about what it  
means, and goes well with the not making it look like line noise.

method to_array (Str $arg) returns ArrayRef[Str] {
     return split /,/, $argl
}

I assume you'd do that by wrapping the actual method in another sub?  
Have you decided if you are going to care about caller being wrong?  
Also what action would you take when the return type isn't what is  
claimed it should be?

-ash


More information about the Perl5-syntax mailing list