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*)&PL_sv_undef && (hv = GvHV(gv))) {
30 SV** svp = (SV**)hv_fetch(hv, name, len, FALSE);
31 if (svp && (sv = *svp) != (SV*)&PL_sv_undef)
35 gvp = (GV**)hv_fetch(stash,"ISA",3,FALSE);
37 if (gvp && (gv = *gvp) != (GV*)&PL_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 if (ckWARN(WARN_MISC))
59 "Can't locate package %s for @%s::ISA",
60 SvPVX(sv), HvNAME(stash));
63 if(&PL_sv_yes == isa_lookup(basestash, name, len, level + 1)) {
64 (void)hv_store(hv,name,len,&PL_sv_yes,0);
68 (void)hv_store(hv,name,len,&PL_sv_no,0);
72 return boolSV(strEQ(name, "UNIVERSAL"));
76 sv_derived_from(SV *sv, char *name)
90 type = sv_reftype(sv,0);
95 stash = gv_stashsv(sv, FALSE);
98 return (type && strEQ(type,name)) ||
99 (stash && isa_lookup(stash, name, strlen(name), 0) == &PL_sv_yes)
107 #endif /* PERL_OBJECT */
119 croak("Usage: UNIVERSAL::isa(reference, kind)");
122 name = (char *)SvPV(ST(1),n_a);
124 ST(0) = boolSV(sv_derived_from(sv, name));
138 croak("Usage: UNIVERSAL::can(object-ref, method)");
141 name = (char *)SvPV(ST(1),n_a);
150 pkg = gv_stashsv(sv, FALSE);
154 GV *gv = gv_fetchmethod_autoload(pkg, name, FALSE);
156 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*)&PL_sv_undef && (sv = GvSV(gv))) {
186 SV *nsv = sv_newmortal();
192 sv = (SV*)&PL_sv_undef;
196 if (items > 1 && (undef || (req = SvNV(ST(1)), req > SvNV(sv)))) {
198 croak("%s version %s required--this is only version %s",
199 HvNAME(pkg), SvPV(ST(1),n_a), undef ? undef : SvPV(sv,n_a));
208 #undef boot_core_UNIVERSAL
209 #define boot_core_UNIVERSAL CPerlObj::Perl_boot_core_UNIVERSAL
214 boot_core_UNIVERSAL(void)
216 char *file = __FILE__;
218 newXS("UNIVERSAL::isa", XS_UNIVERSAL_isa, file);
219 newXS("UNIVERSAL::can", XS_UNIVERSAL_can, file);
220 newXS("UNIVERSAL::VERSION", XS_UNIVERSAL_VERSION, file);