[Perl5-syntax] How to test for a role in a method signature

Reverend Chip rev.chip at gmail.com
Fri Mar 4 10:29:30 GMT 2011


On 3/4/2011 1:57 AM, Piers Cawley wrote:
> On Fri, Mar 4, 2011 at 7:16 AM, Reverend Chip <rev.chip at gmail.com> wrote:
>> On 3/3/2011 10:32 PM, Piers Cawley wrote:
>>> Personally, I prefer the flow of 'Typed $parameter does coerce', where
>>> the constraint declaration is always to the left of the parameter name
>>> and the right hand side is for declaring stuff about how the parameter
>>> is initialized. I would encourage anyone wanting to constrain by type
>>> to declare a type along the lines of "subtype DoesRole, as role_type
>>> 'Role'" ...
>> No, I don't buy it.  The "isa" and "does" tests are so fundamental and
>> common that forcing people to type that much to get the test would
>> violate Huffman.
> That's why I think that the better solution is to delegate to the
> package to find out if a particular value satisfies it. If the package
> is a class, then obviously it does an 'isa' test, if a role, then it
> does a 'does' check and, if a type constraint, it uses the type's
> constraints.

And for combining?  You only get one name to the left.


>  That way you'd use the same syntax to constrain the
> argument whether it be a class, a role or a moose type, rather than
> the proposed idea where you use one syntax if it's a class or a role,
> and different syntax if it's a Role. Similar things should look
> similar, after all.
>
>> Count me as favoring "$x does Foo".
>>
>>
>> _______________________________________________
>> Perl5-syntax mailing list
>> Perl5-syntax at lists.scsys.co.uk
>> http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/perl5-syntax
>>




More information about the Perl5-syntax mailing list