Traits can be mean, but roles are "guarenteed"(=forced?) to play nice. But
suppose I have a role that wants to play nicer, by ensuring that
incorporating it in some class actually makes sense.

For example, it may want to ensure that the class has $.foo. (*)

I have a few questions:

1: Can this be achieved by a CHECK {} block in the role, that gets run
just before the class composition is over? Or should it be spelled
differently, CHECK {} being the last thing that run before "run-time"?

2: What is the syntax for checking that a class has a variable? In this
case the class does not even really exist when we want to check.

3: If arbitrary things can go into such a CHECK{} block, then the
following two may not mean the same:
        does A does B;
        does B does A;
Are roles I<expected> to play nice, or I<forced> to play nice?


--abhijit

(*) The solution "add a C<has $.foo> to the role itself, and if the class
has a $.foo, it takes precedence" does not work because $.foo may have
been added by another role.

Abhijit Mahabal      http://www.cs.indiana.edu/~amahabal/

Reply via email to