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

Buddy Burden barefootcoder at gmail.com
Tue Mar 8 04:15:01 GMT 2011


Michael,

> The downside of resolving types at compile time is if a... whatever[1] isn't
> loaded before your method compiles it will be treated as something you don't
> expect.  And we don't want to force people to load classes at compile time
> just so the types resolve at compile time.  That means they can't be run
> selectively at runtime.

Ah, good point.  I figured there must be a reason I wasn't actually
doing it that way, I just couldn't think what it was. :)

> A simpler approach would be for MXD to special case "does coerce" in parsing.
>  If it sees a role called "coerce" while parsing it warns.  Ta da!

Okay.  I'll keep that in mind once I move on from MS hacking to MXD hacking.

> [1] What are we calling these class/type/role things?

Good question.  In my head, I just call them "types" ... when you say
"Foo::Bar $foo", the "Foo::Bar" part isn't _technically_ a class; it's
actually a type that happens to correspond to a class.  But I suppose
that's really a semantic distinction (and/or an implementation
detail).  We could refer to them as "constraints" I suppose ... type
constraints, class constraints, and role constraints. <shrug>


            -- Buddy



More information about the Perl5-syntax mailing list