Prior Nacre V has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to put together some information on typeglob slots.

Does anyone know if a full list of typeglob slot names (i.e. the THING part of *foo{THING}) exists anywhere?

I've identified these (from various sources):

THINGMeaning
PACKAGEPackage name
NAMETypeglob name
SCALARscalar ref
ARRAYarray ref
HASHhash ref
CODEcode ref
GLOBglob ref
IOio ref - see below
FORMATformat (but need 5.8)
FILEHANDLEsynonym for IO

The *foo{IO} apparently holds sockets, file handles and directory handles but the last two are supposed to have their own namespaces. What whould *X{IO} return following open(X, ...) and opendir(X, ...)?

What about other reference types: REF? Regexp? LVALUE? Any I've missed?

Are there other types of THINGs?

PN5

Replies are listed 'Best First'.
Re: Typeglob Slot Information
by Juerd (Abbot) on Mar 07, 2004 at 22:27 UTC

    Does anyone know if a full list of typeglob slot names (i.e. the THING part of *foo{THING}) exists anywhere?

    I think you just wrote one. :)

    What about other reference types: REF? Regexp? LVALUE? Any I've missed?

    Reference types don't necessarily correspond to equally named glob slots. For example, REF and LVALUE are both of type SCALAR and when put in a glob would live in SCALAR. (I still think that UNIVERSAL::isa(\[], 'SCALAR') should return true.)

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

      I hadn't thought of using isa(). Was thinking more of output from ref(). I'll investigate that.

      PN5

        I hadn't thought of using isa(). Was thinking more of output from ref(). I'll investigate that.

        Both have nothing to do with typeglob slots, except for sometimes identical names. AFAICT, your list is complete as it is. See PP(pp_gelem) in pp.c. For your convienience pasted here:

        Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: Typeglob Slot Information
by ysth (Canon) on Mar 09, 2004 at 03:11 UTC
    The *foo{IO} apparently holds sockets, file handles and directory handles but the last two are supposed to have their own namespaces. What whould *X{IO} return following open(X, ...) and opendir(X, ...)?
    They share the *X{IO} thingy. *X{IO} will be a single PVIO struct which has some fields used for dirs and some used for filehandles.

    What about other reference types: REF? Regexp? LVALUE? Any I've missed?
    REF and LVALUE are just types of scalars. The things ref() returns don't have a one-to-one correspondence with typeglob slots. ref \*STDOUT is "GLOB". In 5.9.0 and above, ref \v1.2.3 will be "VSTRING". Regexp is just a package name. qr// is just a reference to a blessed scalar with some magic attached to store the regex. Scalar::Util::reftype(qr/foo/) is just "SCALAR".

    NAME and PACKAGE aren't really typeglob slots. If you say *A = *B they don't get aliased. They're just info about the glob itself.

Re: Typeglob Slot Information
by ambrus (Abbot) on Mar 09, 2004 at 14:57 UTC

    You can find the full list in the source of the the pp_gelem function, in pp.c.

    ... switch (elem ? *elem : '\0') { case 'A': if (strEQ(elem, "ARRAY")) tmpRef = (SV*)GvAV(gv); break; case 'C': if (strEQ(elem, "CODE")) tmpRef = (SV*)GvCVu(gv); break; case 'F': if (strEQ(elem, "FILEHANDLE")) { /* finally deprecated in 5.8.0 */ deprecate("*glob{FILEHANDLE}"); tmpRef = (SV*)GvIOp(gv); } else if (strEQ(elem, "FORMAT")) tmpRef = (SV*)GvFORM(gv); break; case 'G': if (strEQ(elem, "GLOB")) tmpRef = (SV*)gv; break; case 'H': if (strEQ(elem, "HASH")) tmpRef = (SV*)GvHV(gv); break; case 'I': if (strEQ(elem, "IO")) tmpRef = (SV*)GvIOp(gv); break; case 'N': if (strEQ(elem, "NAME")) sv = newSVpvn(GvNAME(gv), GvNAMELEN(gv)); break; case 'P': if (strEQ(elem, "PACKAGE")) sv = newSVpv(HvNAME(GvSTASH(gv)), 0); break; case 'S': if (strEQ(elem, "SCALAR")) tmpRef = GvSV(gv); break; } ...

    So, it seems that your list is complete.

      Next time, please read the thread before replying. It'll save you some time. I already posted this snippet :)

      Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }