/* The SV holding the pointer to the actual object is hidden away in the interpreter. Users aren't supposed to be able to get at it. */ SV* theObjRef = newSV(0); sv_setref_pv( theObjRef, 0, (void*)this ); /* Now we bless a reference to theObj. * PClasses are not hashrefs like normal perl classes. They are a blessed * reference to a pointer to a C++ obj. Phew! * Stuff in the typemap deals with dereferencing the blessed reference. */ SV* theRef = newRV_noinc(theObjRef); //Make a reference to the reference. noinc: when the last reference is gone, theObj should disappear. sv_bless( theRef, gv_stashpv(name.c_str(), GV_ADD) ); sv_setsv(svrep.sv, theRef); # svrep is member var. Its type is just a little convenience wrapper around SV* with some RAII stuff. if (name != "PClass") { // Tell the class on the perl side that it inherits from PClass. std::string class_isa = name + std::string("::ISA"); av_push( get_av(class_isa.c_str(), 1), newSVpv("PClass", 0) ); // If the user provided an XS method to pull XS methods into the perl interpreter, call that. if (booterSub) _bootModule(name, booterSub); // If a "name".pm is in the @INC path, try to load it up. // eval_pv(std::string(std::string("eval qq{ use ") + name + "}").c_str(), true); }