our $AUTHORITY = 'cpan:STEVAN';
my @exports = qw[
- does_role
+ find_meta
+ does_role
search_class_by_role
];
## some utils for the utils ...
-sub _get_meta {
+sub find_meta {
return unless $_[0];
return Class::MOP::get_metaclass_by_name(ref($_[0]) || $_[0]);
}
sub does_role {
my ($class_or_obj, $role) = @_;
- my $meta = _get_meta($class_or_obj);
+ my $meta = find_meta($class_or_obj);
return unless defined $meta;
sub search_class_by_role {
my ($class_or_obj, $role_name) = @_;
- my $meta = _get_meta($class_or_obj);
+ my $meta = find_meta($class_or_obj);
return unless defined $meta;
foreach my $class ($meta->class_precedence_list) {
- my $_meta = _get_meta($class);
+ my $_meta = find_meta($class);
next unless defined $_meta;
=head1 SYNOPSIS
- use Moose::Util qw/does_role search_class_by_role/;
+ use Moose::Util qw/find_meta does_role search_class_by_role/;
+
+ my $meta = find_meta($object) || die "No metaclass found";
if (does_role($object, $role)) {
print "The object can do $role!\n";
=over 4
+=item B<find_meta ($class_or_obj)>
+
+This will attempt to locate a metaclass for the given C<$class_or_obj>
+and return it.
+
=item B<does_role ($class_or_obj, $role_name)>
Returns true if C<$class_or_obj> can do the role C<$role_name>.
use Sub::Exporter;
use Test::Builder;
+use Moose::Util 'does_role', 'find_meta';
our $VERSION = '0.01';
our $AUTHORITY = 'cpan:STEVAN';
groups => { default => \@exports }
});
-my $Test = Test::Builder->new;
-
-## some helpers ...
+## the test builder instance ...
-sub _get_meta {
- return unless $_[0];
- return Class::MOP::get_metaclass_by_name(ref($_[0]) || $_[0]);
-}
+my $Test = Test::Builder->new;
## exported functions
$message ||= "The object has a meta";
- if (_get_meta($class_or_obj)) {
+ if (find_meta($class_or_obj)) {
return $Test->ok(1, $message)
}
else {
$message ||= "The object does $does";
- my $meta = _get_meta($class_or_obj);
-
- if ($meta->does_role($does)) {
+ if (does_role($class_or_obj, $does)) {
return $Test->ok(1, $message)
}
else {
$message ||= "The object does has an attribute named $attr_name";
- my $meta = _get_meta($class_or_obj);
+ my $meta = find_meta($class_or_obj);
if ($meta->find_attribute_by_name($attr_name)) {
return $Test->ok(1, $message)