[Perl5-syntax] Syntax for Method Traits

Cory Watson jheephat at gmail.com
Thu May 7 12:25:51 GMT 2009


rafl asked me to come to p5-syntax to proffer my work on method traits
and to wrangle up any suggestions for syntax.  At present, I've got a
fork of MooseX::Method::Signatures on github[0] that works with the
following:

method foo(Str :$foo) is Trait1 {

This applies Trait1 to the meta-method. The project I'm working on,
however, desires something slightly more complex:

method foo(Str :$foo) is Trait1(attr => 'value') {

My aforementioned fork of MX:Method::Signatures does not yet deal with
this form, nor does it deal with multiple traits, which I envision
looking like:

method foo(Str :$foo) is Trait1(attr => 'value'), Trait2 {

I've read up on the p6 trait stuff and whatever else Google could
dredge up about method traits and not found a lot.  The only blurb I
found of note was in Perl6::Subs (which I don't know to be
authoritative, but the author likely knows more than me) that the
following are synonymous:

method foo(Str :$foo) is Trait1 {

and

method foo(Str :$foo) : Trait1 {

If that's a true statement then it would be trivial to modify
MX::Method::Signatures to honor it.

rafl's suggestion to come here with this also carried the question as
to this being in Method::Signatures at all.

So, to conclude: Anyone got any recommendations here?  I've got the
tuits to work this out and rafl has displayed the patience of a saint
in guiding me along. ;)

0 - http://github.com/gphat/moosex-method-signatures/tree/master

-- 
Cory 'G' Watson
http://www.onemogin.com



More information about the Perl5-syntax mailing list