Is it possible to do something like?
http://search.cpan.org/dist/Moose/lib/Moose/Manual/Roles.pod goes into detail on how to apply roles, but not if it's possible to query themif ( $class->has_role('xyz') ) { [...] }
Verbose explanation:
I have a couple of roles that the objects can consume. Let's say they provide some functionality for interfacing with the filesystem and the roles are 'Readable' and 'Writeable'. I think it would be very nifty to simply ask an object if it implements/consumes the role 'Writeable' and if it doesn't then I can issue some kind of notification.
The naive implementation would be to check for $obj->write() or similiar, but there may be more then one methods to 'change something' and I don't really want to check every one of them for presence. (Sooner or later one of these methods ~will~ be forgotten.)
In reply to Moose: How to check if a class implements a role? by Monk::Thomas
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |