Monk::Thomas has asked for the wisdom of the Perl Monks concerning the following question:
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.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Moose: How to check if a class implements a role? (does)
by Anonymous Monk on Jul 12, 2013 at 14:59 UTC | |
by daxim (Curate) on Jul 12, 2013 at 15:44 UTC | |
by Monk::Thomas (Friar) on Jul 19, 2013 at 07:52 UTC | |
|
Re: Moose: How to check if a class implements a role?
by tobyink (Canon) on Jul 13, 2013 at 07:27 UTC |