5 * Contributed by Graham Barr <Graham.Barr@tiuk.ti.com>
6 * The main guts of traverse_isa was actually copied from gv_fetchmeth
10 isa_lookup(HV *stash, char *name, int len, int level)
20 if(strEQ(HvNAME(stash), name))
24 croak("Recursive inheritance detected in package '%s'", HvNAME(stash));
26 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, FALSE);
28 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (hv = GvHV(gv))) {
30 SV** svp = (SV**)hv_fetch(hv, name, len, FALSE);
31 if (svp && (sv = *svp) != (SV*)&sv_undef)
35 gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
37 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (av = GvAV(gv))) {
39 gvp = (GV**)hv_fetch(stash, "::ISA::CACHE::", 14, TRUE);
43 if (SvTYPE(gv) != SVt_PVGV)
44 gv_init(gv, stash, "::ISA::CACHE::", 14, TRUE);
49 SV** svp = AvARRAY(av);
50 /* NOTE: No support for tied ISA */
51 I32 items = AvFILLp(av) + 1;
54 HV* basestash = gv_stashsv(sv, FALSE);
57 warn("Can't locate package %s for @%s::ISA",
58 SvPVX(sv), HvNAME(stash));
61 if(&sv_yes == isa_lookup(basestash, name, len, level + 1)) {
62 (void)hv_store(hv,name,len,&sv_yes,0);
66 (void)hv_store(hv,name,len,&sv_no,0);
70 return boolSV(strEQ(name, "UNIVERSAL"));
74 sv_derived_from(SV *sv, char *name)
88 type = sv_reftype(sv,0);
93 stash = gv_stashsv(sv, FALSE);
96 return (type && strEQ(type,name)) ||
97 (stash && isa_lookup(stash, name, strlen(name), 0) == &sv_yes)
105 #endif /* PERL_OBJECT */
117 croak("Usage: UNIVERSAL::isa(reference, kind)");
120 name = (char *)SvPV(ST(1),na);
122 ST(0) = boolSV(sv_derived_from(sv, name));
136 croak("Usage: UNIVERSAL::can(object-ref, method)");
139 name = (char *)SvPV(ST(1),na);
148 pkg = gv_stashsv(sv, FALSE);
152 GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
154 rv = sv_2mortal(newRV((SV*)GvCV(gv)));
162 XS(XS_UNIVERSAL_VERSION)
173 sv = (SV*)SvRV(ST(0));
175 croak("Cannot find version of an unblessed reference");
179 pkg = gv_stashsv(ST(0), FALSE);
182 gvp = pkg ? (GV**)hv_fetch(pkg,"VERSION",7,FALSE) : Null(GV**);
184 if (gvp && (gv = *gvp) != (GV*)&sv_undef && (sv = GvSV(gv))) {
185 SV *nsv = sv_newmortal();
195 if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv))))
196 croak("%s version %s required--this is only version %s",
197 HvNAME(pkg), SvPV(ST(1),na), undef ? undef : SvPV(sv,na));
205 #undef boot_core_UNIVERSAL
206 #define boot_core_UNIVERSAL CPerlObj::Perl_boot_core_UNIVERSAL
211 boot_core_UNIVERSAL(void)
213 char *file = __FILE__;
215 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
216 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
217 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);