Re: embedded perl and top_env problem
[p5sagit/p5-mst-13.2.git] / universal.c
index ea797ae..03b907d 100644 (file)
@@ -134,6 +134,7 @@ XS(XS_UNIVERSAL_can)
     SV   *rv;
     GV   *gv;
     CV   *cvp;
+    HV   *pkg = NULL;
 
     if (items != 2)
        croak("Usage: UNIVERSAL::can(object-ref, method)");
@@ -142,8 +143,17 @@ XS(XS_UNIVERSAL_can)
     name = (char *)SvPV(ST(1),na);
     rv = &sv_undef;
 
-    if(SvROK(sv) && (sv = (SV*)SvRV(sv)) && SvOBJECT(sv)) {
-        gv = gv_fetchmethod(SvSTASH(sv), name);
+    if(SvROK(sv)) {
+        sv = (SV*)SvRV(sv);
+        if(SvOBJECT(sv))
+            pkg = SvSTASH(sv);
+    }
+    else {
+        pkg = gv_stashsv(sv, FALSE);
+    }
+
+    if (pkg) {
+        gv = gv_fetchmethod(pkg, name);
 
         if(gv && GvCV(gv)) {
             /* If the sub is only a stub then we may have a gv to AUTOLOAD */
@@ -160,26 +170,6 @@ XS(XS_UNIVERSAL_can)
 }
 
 static
-XS(XS_UNIVERSAL_is_instance)
-{
-    dXSARGS;
-    ST(0) = SvROK(ST(0)) ? &sv_yes : &sv_no;
-    XSRETURN(1);
-}
-
-static
-XS(XS_UNIVERSAL_class)
-{
-    dXSARGS;
-    if(SvROK(ST(0)) && SvOBJECT(SvRV(ST(0)))) {
-        SV *sv = sv_newmortal();
-        sv_setpv(sv, HvNAME(SvSTASH(SvRV(ST(0)))));
-        ST(0) = sv;
-    }
-    XSRETURN(1);
-}
-
-static
 XS(XS_UNIVERSAL_VERSION)
 {
     dXSARGS;
@@ -188,6 +178,7 @@ XS(XS_UNIVERSAL_VERSION)
     GV *gv;
     SV *sv;
     char *undef;
+    double req;
 
     if(SvROK(ST(0))) {
         sv = (SV*)SvRV(ST(0));
@@ -212,9 +203,9 @@ XS(XS_UNIVERSAL_VERSION)
         undef = "(undef)";
     }
 
-    if(items > 1 && (undef || SvNV(ST(1)) > SvNV(sv)))
+    if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv))))
        croak("%s version %s required--this is only version %s",
-           HvNAME(pkg),SvPV(ST(1),na),undef ? undef : SvPV(sv,na));
+             HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na));
 
     ST(0) = sv;
 
@@ -228,7 +219,5 @@ boot_core_UNIVERSAL()
 
     newXS("UNIVERSAL::isa",             XS_UNIVERSAL_isa,         file);
     newXS("UNIVERSAL::can",             XS_UNIVERSAL_can,         file);
-    newXS("UNIVERSAL::class",           XS_UNIVERSAL_class,       file);
-    newXS("UNIVERSAL::is_instance",     XS_UNIVERSAL_is_instance, file);
     newXS("UNIVERSAL::VERSION",        XS_UNIVERSAL_VERSION,     file);
 }