Ok.  This doesn't really make sense.  Here is the problem:  A role is
applied to a class, not an object (technically you can apply it to an
object with Moose::Util::apply_all_roles, but this seems like a Bad
Idea).  A class doesn't have attributes (well there's a module for
that, but let's ignore that for the time being).  A class has methods.
So you can test if a method exists, but not if that method returns a
particular value.

-Edward

On Thu, Jan 12, 2012 at 2:57 PM, Mark Hedges <[email protected]> wrote:
>
> Hi.  I'm trying to figure out how a role, when applied to an
> object, can verify that the object already has a particular
> attribute and that its conents equal some string.  Am I
> missing something in the cookbook?  It is sort of backwards
> from the usual way that an object requires the role can do
> something or has an attribute.
>
> I want to cross check when the role gets applied that the
> role has everything in the object that the methods it
> supplies needs to work.
>
> I suppose I can just verify this when methods run and then
> throw an error to say the role got applied to the wrong
> object, but I'd rather throw that from the place that I
> apply the role.
>
> Mark
>

Reply via email to