Make the XS version of is_class_loaded smarter about handling corner
Dave Rolsky [Sun, 8 Feb 2009 16:41:11 +0000 (16:41 +0000)]
cases where a VERSION entry in the stash exists but we haven't
_really_ loaded the class yet.

MOP.xs

diff --git a/MOP.xs b/MOP.xs
index 38994c5..07b2fb8 100644 (file)
--- a/MOP.xs
+++ b/MOP.xs
@@ -364,8 +364,18 @@ is_class_loaded(klass=&PL_sv_undef)
 
         if (hv_exists_ent (stash, key_VERSION, hash_VERSION)) {
             HE *version = hv_fetch_ent(stash, key_VERSION, 0, hash_VERSION);
-            if (version && HeVAL(version) && GvSV(HeVAL(version))) {
-                XSRETURN_YES;
+            SV *version_sv;
+            if (version && HeVAL(version) && (version_sv = GvSV(HeVAL(version)))) {
+                if (SvROK(version_sv)) {
+                    SV *version_sv_ref = SvRV(version_sv);
+
+                    if (SvOK(version_sv_ref)) {
+                        XSRETURN_YES;
+                    }
+                }
+                else if (SvOK(version_sv)) {
+                    XSRETURN_YES;
+                }
             }
         }