From: Stevan Little Date: Sun, 12 Aug 2007 15:04:50 +0000 (+0000) Subject: restored the coupling; X-Git-Tag: 0_25~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6532ca5a12ab6a7df41bdd5238878a47d4514249;p=gitmo%2FMoose.git restored the coupling; --- diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index 113f6b1..e9d2f25 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -11,7 +11,8 @@ our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; my @exports = qw[ - does_role + find_meta + does_role search_class_by_role ]; @@ -22,7 +23,7 @@ Sub::Exporter::setup_exporter({ ## some utils for the utils ... -sub _get_meta { +sub find_meta { return unless $_[0]; return Class::MOP::get_metaclass_by_name(ref($_[0]) || $_[0]); } @@ -32,7 +33,7 @@ sub _get_meta { 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; @@ -43,13 +44,13 @@ sub does_role { 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; @@ -73,7 +74,9 @@ Moose::Util - Utilities for working with Moose classes =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"; @@ -94,6 +97,11 @@ functions to write. =over 4 +=item B + +This will attempt to locate a metaclass for the given C<$class_or_obj> +and return it. + =item B Returns true if C<$class_or_obj> can do the role C<$role_name>. diff --git a/lib/Test/Moose.pm b/lib/Test/Moose.pm index 58b7e95..3228213 100644 --- a/lib/Test/Moose.pm +++ b/lib/Test/Moose.pm @@ -5,6 +5,7 @@ use warnings; use Sub::Exporter; use Test::Builder; +use Moose::Util 'does_role', 'find_meta'; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; @@ -20,14 +21,9 @@ Sub::Exporter::setup_exporter({ 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 @@ -36,7 +32,7 @@ sub meta_ok ($;$) { $message ||= "The object has a meta"; - if (_get_meta($class_or_obj)) { + if (find_meta($class_or_obj)) { return $Test->ok(1, $message) } else { @@ -49,9 +45,7 @@ sub does_ok ($$;$) { $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 { @@ -64,7 +58,7 @@ sub has_attribute_ok ($$;$) { $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)