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);
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) = (sv_derived_from(sv, name) ? &sv_yes : &sv_no) ;
140 croak("Usage: UNIVERSAL::can(object-ref, method)");
143 name = (char *)SvPV(ST(1),na);
152 pkg = gv_stashsv(sv, FALSE);
156 gv = gv_fetchmethod(pkg, name);
159 /* If the sub is only a stub then we may have a gv to AUTOLOAD */
160 GV **gvp = (GV**)hv_fetch(GvSTASH(gv), name, strlen(name), TRUE);
161 if(gvp && (cvp = GvCV(*gvp))) {
163 sv_setsv(rv, newRV((SV*)cvp));
173 XS(XS_UNIVERSAL_VERSION)
184 sv = (SV*)SvRV(ST(0));
186 croak("Cannot find version of an unblessed reference");
190 pkg = gv_stashsv(ST(0), FALSE);
193 gvp = pkg ? (GV**)hv_fetch(pkg,"VERSION",7,FALSE) : Null(GV**);
195 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (sv = GvSV(gv))) {
196 SV *nsv = sv_newmortal();
206 if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv))))
207 croak("%s version %s required--this is only version %s",
208 HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na));
216 boot_core_UNIVERSAL()
218 char *file = __FILE__;
220 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
221 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
222 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);