Move class_of into the scope of %METAS to save a method call (since it's
Shawn M Moore [Sat, 28 Mar 2009 22:15:19 +0000 (18:15 -0400)]
so hot!)

lib/Class/MOP.pm

index e1c4579..e4962e9 100644 (file)
@@ -59,6 +59,12 @@ XSLoader::load( __PACKAGE__, $XS_VERSION );
     sub does_metaclass_exist        { exists $METAS{$_[0]} && defined $METAS{$_[0]} }
     sub remove_metaclass_by_name    { $METAS{$_[0]} = undef }
 
+    # This handles instances as well as class names
+    sub class_of {
+        my $class = blessed($_[0]) || $_[0];
+        return $METAS{$class};
+    }
+
     # NOTE:
     # We only cache metaclasses, meaning instances of
     # Class::MOP::Class. We do not cache instance of
@@ -136,11 +142,6 @@ sub _is_valid_class_name {
     return 0;
 }
 
-sub class_of {
-    my $class = blessed($_[0]) || $_[0];
-    return get_metaclass_by_name($class);
-}
-
 ## ----------------------------------------------------------------------------
 ## Setting up our environment ...
 ## ----------------------------------------------------------------------------