10 our $VERSION = '0.01';
11 our $AUTHORITY = 'cpan:STEVAN';
18 Sub::Exporter::setup_exporter({
20 groups => { default => \@exports }
23 ## some utils for the utils ...
27 return Class::MOP::get_metaclass_by_name(ref($_[0]) || $_[0]);
33 my ($class_or_obj, $role) = @_;
35 my $meta = _get_meta($class_or_obj);
37 return unless defined $meta;
39 return 1 if $meta->does_role($role);
43 sub search_class_by_role {
44 my ($class_or_obj, $role_name) = @_;
46 my $meta = _get_meta($class_or_obj);
48 return unless defined $meta;
50 foreach my $class ($meta->class_precedence_list) {
52 my $_meta = _get_meta($class);
54 next unless defined $_meta;
56 foreach my $role (@{ $_meta->roles || [] }) {
57 return $class if $role->name eq $role_name;
72 Moose::Util - Utilities for working with Moose classes
76 use Moose::Util qw/does_role search_class_by_role/;
78 if (does_role($object, $role)) {
79 print "The object can do $role!\n";
82 my $class = search_class_by_role($object, 'FooRole');
83 print "Nearest class with 'FooRole' is $class\n";
87 This is a set of utility functions to help working with Moose classes. This
88 is an experimental module, and it's not 100% clear what purpose it will serve.
89 That said, ideas, suggestions and contributions to this collection are most
90 welcome. See the L<TODO> section below for a list of ideas for possible
93 =head1 EXPORTED FUNCTIONS
97 =item B<does_role ($class_or_obj, $role_name)>
99 Returns true if C<$class_or_obj> can do the role C<$role_name>.
101 =item B<search_class_by_role ($class_or_obj, $role_name)>
103 Returns first class in precedence list that consumed C<$role_name>.
109 Here is a list of possible functions to write
113 =item discovering original method from modified method
115 =item search for origin class of a method or attribute
121 All complex software has bugs lurking in it, and this module is no
122 exception. If you find a bug please either email me, or add the bug
127 Anders Nor Berle E<lt>debolaz@gmail.comE<gt>
129 B<with contributions from:>
131 Robert (phaylon) Sedlacek
135 =head1 COPYRIGHT AND LICENSE
137 Copyright 2007 by Infinity Interactive, Inc.
139 L<http://www.iinteractive.com>
141 This library is free software; you can redistribute it and/or modify
142 it under the same terms as Perl itself.