6 * Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
7 * The main guts of traverse_isa was actually copied from gv_fetchmeth
11 isa_lookup(HV *stash, char *name, int len, int level)
21 if(strEQ(HvNAME(stash), name))
25 croak("Recursive inheritance detected");
27 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, FALSE);
29 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (hv = GvHV(gv))) {
31 SV** svp = (SV**)hv_fetch(hv, name, len, FALSE);
32 if (svp && (sv = *svp) != (SV*)&sv_undef)
36 gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
38 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
40 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, TRUE);
44 if (SvTYPE(gv) != SVt_PVGV)
45 gv_init(gv, stash, "::ISA::CACHE::", 14, TRUE);
50 SV** svp = AvARRAY(av);
51 /* NOTE: No support for tied ISA */
52 I32 items = AvFILLp(av) + 1;
55 HV* basestash = gv_stashsv(sv, FALSE);
58 warn("Can't locate package %s for @%s::ISA",
59 SvPVX(sv), HvNAME(stash));
62 if(&sv_yes == isa_lookup(basestash, name, len, level + 1)) {
63 (void)hv_store(hv,name,len,&sv_yes,0);
67 (void)hv_store(hv,name,len,&sv_no,0);
71 return boolSV(strEQ(name, "UNIVERSAL"));
75 sv_derived_from(SV *sv, char *name)
89 type = sv_reftype(sv,0);
94 stash = gv_stashsv(sv, FALSE);
97 return (type && strEQ(type,name)) ||
98 (stash && isa_lookup(stash, name, strlen(name), 0) == &sv_yes)
113 croak("Usage: UNIVERSAL::isa(reference, kind)");
116 name = (char *)SvPV(ST(1),na);
118 ST(0) = boolSV(sv_derived_from(sv, name));
132 croak("Usage: UNIVERSAL::can(object-ref, method)");
135 name = (char *)SvPV(ST(1),na);
144 pkg = gv_stashsv(sv, FALSE);
148 GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
150 rv = sv_2mortal(newRV((SV*)GvCV(gv)));
158 XS(XS_UNIVERSAL_VERSION)
169 sv = (SV*)SvRV(ST(0));
171 croak("Cannot find version of an unblessed reference");
175 pkg = gv_stashsv(ST(0), FALSE);
178 gvp = pkg ? (GV**)hv_fetch(pkg,"VERSION",7,FALSE) : Null(GV**);
180 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (sv = GvSV(gv))) {
181 SV *nsv = sv_newmortal();
191 if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv))))
192 croak("%s version %s required--this is only version %s",
193 HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na));
201 boot_core_UNIVERSAL(void)
203 char *file = __FILE__;
205 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
206 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
207 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);