use MRO::Compat;
use Carp 'confess';
-use Scalar::Util 'weaken';
+use Scalar::Util qw/weaken blessed/;
use Class::MOP::Class;
die $e if $e && $e !~ /object version|loadable object/;
return $e ? 0 : 1;
-}
+ }
sub _load_pure_perl {
require Sub::Identify;
sub does_metaclass_exist { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
sub remove_metaclass_by_name { $METAS{$_[0]} = undef }
+ sub get_meta { $METAS{ blessed($_[0]) || $_[0] } }
+
# NOTE:
# We only cache metaclasses, meaning instances of
# Class::MOP::Class. We do not cache instance of
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 4;
+
+require Class::MOP;
+
+is(Class::MOP::get_meta('Does::Not::Exist'), undef, "... get_meta on a nonexistent class returns undef");
+is(Class::MOP::get_meta(bless {}, 'Does::Not::Exist'), undef, "... get_meta on an instance of a nonexistent class returns undef");
+
+is(Class::MOP::get_meta('Class::MOP::Class'), Class::MOP::Class->meta, "... get_meta on Class::MOP::Class returns its metaclass");
+is(Class::MOP::get_meta(bless {}, 'Class::MOP::Class'), Class::MOP::Class->meta, "... get_meta on an instance of Class::MOP::Class returns its metaclass");
+