3 use Exporter qw/import/;
4 use Scalar::Util qw/blessed/;
11 our $AUTHORITY = 'cpan:BERLE';
13 our @EXPORT_OK = qw/can_role search_class_by_role/;
16 my ($class,$does) = @_;
18 return ((!ref $class && eval { $class->isa ('UNIVERSAL') }) || Scalar::Util::blessed ($class))
19 && $class->can ('does')
20 && $class->does ($does);
23 sub search_class_by_role {
24 my ($obj, $role_name) = @_;
26 for my $class ($obj->meta->class_precedence_list) {
27 for my $role (@{ $class->meta->roles || [] }) {
28 return $class if $role->name eq $role_name;
43 Moose::Util - Moose utilities
47 use Moose::Util qw/can_role search_class_by_role/;
49 if (can_role ($object,'rolename')) {
50 print "The object can do rolename!\n";
53 my $class = search_class_by_role($object, 'FooRole');
54 print "Nearest class with 'FooRole' is $class\n";
62 can_role ($object,$rolename);
64 Returns true if $object can do the role $rolename.
66 =item search_class_by_role
68 my $class = search_class_by_role($object, $rolename);
70 Returns first class in precedence list that consumed C<$rolename>.
76 All complex software has bugs lurking in it, and this module is no
77 exception. If you find a bug please either email me, or add the bug
82 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
84 =head1 COPYRIGHT AND LICENSE
86 Copyright 2007 by Infinity Interactive, Inc.
88 L<http://www.iinteractive.com>
90 This library is free software; you can redistribute it and/or modify
91 it under the same terms as Perl itself.