[Perl5-syntax] Adding Moose type checking to Method::Signatures

Buddy Burden barefootcoder at gmail.com
Fri Mar 4 01:10:29 GMT 2011


Michael,

>>     method foo ($bar does Executable)
>>     {
>>         # now I know I can do this
>>         $bar->exec();
>>     }
>
> It's a good idea, I'm sold on roles, and it makes sense to me.  It's something
> that should be discussed with the list.  Fire off a different thread, because
> I'm pretty sure nobody but us is reading this one.

Heh.  Fair enough.  I'll do that shortly.

> I'm also not sure it's actual Perl 6 syntax.  I don't see any example of it
> either in the Perl 6 synopsis or rakudo code.  Might just be in chromatic's head.

Yeah, maybe there's a different syntax.  I just spent a little time
searching through the synopses and didn't see it.  Hopefully someone
on list knows.

>>> Since Method::Signatures is lexical, I don't see how you'd write code with a
>>> feature if you didn't intend to use it.  I'd go with an error.  At least you
>>> can easily trap an error.
>>
>> Actually the way I've done it thus far (I've officially started the
>> hacking; woohoo!) is like so:
>>
>>     use Method::Signatures { warn => 0 };
>> :
>> :
> I'm happy with it just dying.  I'd rather see time spent implementing the
> unimplemented behaviors than elaborate ways to configure them when they're
> missing.  If that's your itch, ok.

Oh, I already did it (did it back on Tuesday, actually).  The thing
about dying is that it's _not_ actually easier to trap, since it
happens at compile time.  E.g. in many of my tests, I've had to eval
the method declarations as a string.  Which is fine for tests, but
ugly if you had to do that in code.  So I think even if we change the
warn to a die, we'll still want to have a parameter to turn it off.

I don't much care either way.  We can do warn, we can do die, or we
can do either, depending on the 'use' call.  Your choice.  It's pretty
trivial to implement it any of those ways now that I have all the
tests working.

> I like `use Method::Signatures { warn => 0 };` because it can translate
> directly to passing those parameters straight along to the internal object.
> That keeps us from having to write more import syntax for everything we want
> configurable.

Sure.  I'm just more used to

    use Method::Signatures ( warn => 0 );

style.  But, as I say, I didn't want to hack up import() to the point
where it would support that, so I just stuck with the hashref.


            -- Buddy



More information about the Perl5-syntax mailing list