A GV is a structure which corresponds to to a Perl typeglob, ie *foo. It is a structure that holds a pointer to a scalar, an array, a hash etc, corresponding to $foo, @foo, %foo.
GVs are usually found as values in stashes (symbol table hashes) where Perl stores its global variables.
gv is a typeglob whose subroutine entry is a constant sub eligible for inlining, or
gv is a placeholder reference that would be promoted to such a typeglob, then returns the value returned by the sub. Otherwise, returns NULL.
Converts a scalar into a typeglob. This is an incoercible typeglob; assigning a reference to it will assign to one of its slots, instead of overwriting it as happens with typeglobs created by SvSetSV. Converting any scalar that is SvOK() may produce unpredictable results and is reserved for perl's internal use.
gv is the scalar to be converted.
stash is the parent stash/package, if any.
len give the name. The name must be unqualified; that is, it must not include the package name. If
gv is a stash element, it is the caller's responsibility to ensure that the name passed to this function matches the name of the element. If it does not match, perl's internal bookkeeping will get out of sync.
flags can be set to SVf_UTF8 if
name is a UTF8 string, or the return value of SvUTF8(sv). It can also take the GV_ADDMULTI flag, which means to pretend that the GV has been seen before (i.e., suppress "Used once" warnings).
The old form of gv_init_pvn(). It does not work with UTF8 strings, as it has no flags parameter. If the
multi parameter is set, the GV_ADDMULTI flag will be passed to gv_init_pvn().
Same as gv_init_pvn(), but takes a nul-terminated string for the name instead of separate char * and length parameters.
Same as gv_init_pvn(), but takes an SV * for the name instead of separate char * and length parameters.
flags is currently unused.
Like "gv_fetchmeth_pvn", but lacks a flags parameter.
Exactly like "gv_fetchmeth_pvn", but takes the name string in the form of an SV instead of a string/length pair.
Exactly like "gv_fetchmeth_pvn", but takes a nul-terminated string instead of a string/length pair.
Returns the glob with the given
name and a defined subroutine or
NULL. The glob lives in the given
stash, or in the stashes accessible via @ISA and UNIVERSAL::.
level should be either 0 or -1. If
level==0, as a side-effect creates a glob with the given
name in the given
stash which in the case of success contains an alias for the subroutine, and sets up caching info for this glob.
The only significant values for
flags are GV_SUPER and SVf_UTF8.
GV_SUPER indicates that we want to look up the method in the superclasses of the
The GV returned from
gv_fetchmeth may be a method cache entry, which is not visible to Perl code. So when calling
call_sv, you should not use the GV directly; instead, you should use the method's CV, which can be obtained from the GV with the
This is the old form of "gv_fetchmeth_pvn_autoload", which has no flags parameter.
Exactly like "gv_fetchmeth_pvn_autoload", but takes the name string in the form of an SV instead of a string/length pair.
Exactly like "gv_fetchmeth_pvn_autoload", but takes a nul-terminated string instead of a string/length pair.
Same as gv_fetchmeth_pvn(), but looks for autoloaded subroutines too. Returns a glob for the subroutine.
For an autoloaded subroutine without a GV, will create a GV even if
level < 0. For an autoloaded subroutine without a stub, GvCV() of the result may be zero.
Currently, the only significant value for
flags is SVf_UTF8.
Returns the glob which contains the subroutine to call to invoke the method on the
stash. In fact in the presence of autoloading this may be the glob for "AUTOLOAD". In this case the corresponding variable $AUTOLOAD is already setup.
The third parameter of
gv_fetchmethod_autoload determines whether AUTOLOAD lookup is performed if the given method is not present: non-zero means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD. Calling
gv_fetchmethod is equivalent to calling
gv_fetchmethod_autoload with a non-zero
These functions grant
"SUPER" token as a prefix of the method name. Note that if you want to keep the returned glob for a long time, you need to check for it being "AUTOLOAD", since at the later time the call may load a different subroutine due to $AUTOLOAD changing its value. Use the glob created via a side effect to do this.
These functions have the same side-effects and as
name should be writable if contains
' ''. The warning against passing the GV returned by
call_sv apply equally to these functions.
Returns a pointer to the stash for a specified package. Uses
strlen to determine the length of
name, then calls
Returns a pointer to the stash for a specified package. The
namelen parameter indicates the length of the
name, in bytes.
flags is passed to
gv_fetchpvn_flags(), so if set to
GV_ADD then the package will be created if it does not already exist. If the package does not exist and
flags is 0 (or any other setting that does not create packages) then NULL is returned.
Flags may be one of:
GV_ADD SVf_UTF8 GV_NOADD_NOINIT GV_NOINIT GV_NOEXPAND GV_ADDMG
The most important of which are probably GV_ADD and SVf_UTF8.
Returns a pointer to the stash for a specified package. See
If the typeglob
gv can be expressed more succinctly, by having something other than a real GV in its place in the stash, replace it with the optimised form. Basic requirements for this are that
gv is a real typeglob, is sufficiently ordinary, and is only referenced from its package. This function is meant to be used when a GV has been looked up in part to see what was there, causing upgrading, but based on what was found it turns out that the real GV isn't required after all.
gv is a completely empty typeglob, it is deleted from the stash.
gv is a typeglob containing only a sufficiently-ordinary constant sub, the typeglob is replaced with a scalar-reference placeholder that more compactly represents the same thing.