Re: find attributes type_constraints
[email protected] (Stevan Little)
| Newsgroups | perl.moose |
|---|---|
| Message-ID | <[email protected]> |
Christoph, On May 6, 2007, at 5:42 PM, Ch Lamprecht wrote: > 'ArrayRef' is in the name attribute of the TypeConstraint, but I > don't see a way to get the classname 'TkObjectsView' back out of > the second type_constraint object. Yes, because Moose has never encountered TkObjectsView before, it cannot tell for sure what it is, so as a compromise, it will assume it is an object and give you the ANON type constraint which will do the right thing for that assumption. The reason it does not make an officially named type constraint is that Moose cannot be sure that it *should* do that, and that you won't try to make a type constraint using that name later on, which has an entirely different meaning. > Will I have to explicitly create a 'Moose::Meta::TypeConstraint' > for every class > I want to use in an attribute to make this work? That is one way, but an easier way is to do this: $attr->_isa_metadata; It will give you back the original string from the 'isa' option. There is also a &_does_metadata and &_is_metadata as well. This should be considered a "semi-private" method, which is to say it is not part of the core API, but can be used outside of the class and will not likely change. It is there specifically for introspective uses like yours and is already (ab)used heavily in the Reaction code base IIRC. - Stevan