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(stash, name, len, level)
25 if(strEQ(HvNAME(stash), name))
29 croak("Recursive inheritance detected");
31 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, FALSE);
33 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (hv = GvHV(gv))) {
35 SV** svp = (SV**)hv_fetch(hv, name, len, FALSE);
36 if (svp && (sv = *svp) != (SV*)&sv_undef)
40 gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
42 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
44 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, TRUE);
48 if (SvTYPE(gv) != SVt_PVGV)
49 gv_init(gv, stash, "::ISA::CACHE::", 14, TRUE);
54 SV** svp = AvARRAY(av);
55 I32 items = AvFILL(av) + 1;
58 HV* basestash = gv_stashsv(sv, FALSE);
61 warn("Can't locate package %s for @%s::ISA",
62 SvPVX(sv), HvNAME(stash));
65 if(&sv_yes == isa_lookup(basestash, name, len, level + 1)) {
66 (void)hv_store(hv,name,len,&sv_yes,0);
70 (void)hv_store(hv,name,len,&sv_no,0);
74 return boolSV(strEQ(name, "UNIVERSAL"));
78 sv_derived_from(sv, name)
94 type = sv_reftype(sv,0);
99 stash = gv_stashsv(sv, FALSE);
102 return (type && strEQ(type,name)) ||
103 (stash && isa_lookup(stash, name, strlen(name), 0) == &sv_yes)
118 croak("Usage: UNIVERSAL::isa(reference, kind)");
121 name = (char *)SvPV(ST(1),na);
123 ST(0) = boolSV(sv_derived_from(sv, name));
137 croak("Usage: UNIVERSAL::can(object-ref, method)");
140 name = (char *)SvPV(ST(1),na);
149 pkg = gv_stashsv(sv, FALSE);
153 GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
155 rv = sv_2mortal(newRV((SV*)GvCV(gv)));
163 XS(XS_UNIVERSAL_VERSION)
174 sv = (SV*)SvRV(ST(0));
176 croak("Cannot find version of an unblessed reference");
180 pkg = gv_stashsv(ST(0), FALSE);
183 gvp = pkg ? (GV**)hv_fetch(pkg,"VERSION",7,FALSE) : Null(GV**);
185 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (sv = GvSV(gv))) {
186 SV *nsv = sv_newmortal();
196 if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv))))
197 croak("%s version %s required--this is only version %s",
198 HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na));
206 boot_core_UNIVERSAL()
208 char *file = __FILE__;
210 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
211 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
212 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);