Devel::MAT::SV(3pm)
π Devel::MAT::SV π
okay bestie, this is Devel::MAT::SV(3pm) straight out of your User Contributed Perl Documentation. grab a snack π and get comfy, because we are going through literally every single thing on this page and I am not skipping anything. no cap.
πΈ NAME πΈ
Devel::MAT::SV β represent a single SV from a heap dump π
β¨ DESCRIPTION β¨
So here's the vibe. Objects in this class each represent one individual SV variable that was found hangin' out in the arena during a heap dump. that's the whole job.
And the actual types of SV? They've all got their own subclasses, and every one of them is documented right down below. iconic honestly. π
π COMMON METHODS π
these are shared across all the SV classes. obsessed. anyway:
type
$type = $sv->type;
Returns the major type of the SV. and it's literally just the class name with the Devel::MAT::SV:: prefix chopped off. easy.
basetype
$type = $sv->basetype;
Returns the inner perl API type of the SV. it's one of these bad boys:
SV AV HV CV GV LV PVIO PVFM REGEXP INVLIST OBJ
that's the whole menu, bestie.
desc
$desc = $sv->desc;
Returns a string describing the type of the SV, plus a short lil detail of what's inside it. what exactly you get depends on the SV type β the details are not one-size-fits-all. π
desc_addr
$desc = $sv->desc_addr;
Same energy as desc, except it also gives you the address in hex. super useful when you're printing and need to uniquely identify the SV. chef's kiss.
addr
$addr = $sv->addr;
Returns the address of the SV. period.
refcnt
$count = $sv->refcnt;;
Returns the SvREFCNT reference count of the SV. (yes the double ;; is literally how it's written up there. not me editing the source π)
refcount_adjusted
$count = $sv->refcount_adjusted;
Returns the reference count of the SV β but adjusted, because the SvREFCNT value of the backrefs list of a hash or weakly-referenced object is artificially high. she does the math so you don't have to. β¨
blessed
$stash = $sv->blessed;
If this SV is a blessed object, you get the stash SV back. If it's not? undef. that's it.
symname
$name = $sv->symname;
Call this on an SV that's a member of the symbol table and it hands you the perl representation of the full symbol name, sigil included. not one of those? undef, sorry babe.
Oh and heads up: a leading main:: prefix gets removed for symbols in packages other than main. noted.
size
$size = $sv->size;
Returns the (approximate!) size in bytes of the SV. she's approximate, she's doing her best.
magic
@magics = $sv->magic;
Returns a list of magic applied to the SV. each one gives you the type and the target SVs as struct fields:
$type = $magic->type;
$sv = $magic->obj;
$sv = $magic->ptr;
$ptr = $magic->vtbl;
magic_svs
@svs = $sv->magic_svs;
This is just a more efficient way to grab just the SVs associated with the applied magic. same tea, less work. efficiency queen π
backrefs
$av_or_rv = $sv->backrefs;
Returns the backrefs SV. That might be an AV holding the back references β or, if there's only one, it'll be the REF SV itself that refers to this one. cute.
rootname
$rootname = $sv->rootname;
If the SV is a well-known root, you get its name. If it's not? undef. simple as.
outrefs
@refs = $sv->outrefs;
Returns a list of Reference objects β one for each SV that this one refers to. and "refers to" is doing a LOT of work here, because it counts:
- directly by strong or weak reference
- indirectly via RV
- or inferred by
Devel::MATitself
Each of those objects is a structure with three fields:
name => STRINGβ a human-readable string, for identification purposes.strength => "strong"|"weak"|"indirect"|"inferred"β tells you what kind of reference it is.strongreferences contribute to therefcountof the referrant; the others don't.strongandweakreferences are SV addresses found directly within the referring SV structure;indirectandinferredreferences are extra return values added here for convenience by examining the surrounding structure.sv => SVβ the referrant SV itself.
outrefs_strong
@refs = $sv->outrefs_strong;
The subset of outrefs that are direct strong references. just the strong ones.
outrefs_weak
@refs = $sv->outrefs_weak;
The subset of outrefs that are direct weak references. just the weak ones.
outrefs_direct
@refs = $sv->outrefs_direct;
The subset of outrefs that are direct strong or weak references. both flavors.
outrefs_indirect
@refs = $sv->outrefs_indirect;
The subset of outrefs that are indirect references via RVs.
outrefs_inferred
@refs = $sv->outrefs_inferred;
The subset of outrefs that are not directly stored in the SV structure, but instead inferred by Devel::MAT itself. she figured it out. (accurately.)
outref_named
$ref = $sv->outref_named( $name );
Since version 0.49.
Looks for a reference whose name is exactly the one you passed in, and returns it if it finds it.
β οΈ Throws an exception if the SV has no such outref of that name. so like. be aware, bestie.
maybe_outref_named
$ref = $sv->maybe_outref_named( $name );
Since version 0.49.
Same as outref_named, but returns undef if there's no such reference. the chill version β no exception drama. π«Ά
is_mortal
$mortal = $sv->is_mortal;
Returns true if this SV is referenced by the temps stack. mortal queen π
π IMMORTAL SVs π
Three special SV objects exist outside of the heap, and they're here to represent undef and boolean true and false. They are:
Devel::MAT::SV::UNDEFDevel::MAT::SV::YESDevel::MAT::SV::NO
they live outside the heap. they're above it all. main character energy fr. β¨
π¦ Devel::MAT::SV::GLOB π¦
Represents a glob β an SV of type SVt_PVGV.
file, line, location
$file = $gv->file;
$line = $gv->line;
$location = $gv->location;
Returns the filename, the line number, or the combined location (FILE line LINE) that the GV first appears at. so you know exactly where she showed up. π΅οΈ
name
$name = $gv->name;
Returns the value of the GvNAME field, for named globs.
stash
$stash = $gv->stash;
Returns the stash that the GV belongs to.
scalar, array, hash, code, egv, io, form
$sv = $gv->scalar;
$av = $gv->array;
$hv = $gv->hash;
$cv = $gv->code;
$gv = $gv->egv;
$io = $gv->io;
$form = $gv->form;
Return the SV sitting in the various glob slots. take your pick bestie. π
π Devel::MAT::SV::SCALAR π
Represents a non-referential scalar value β an SV of any of the types up to and including SVt_PVMV (that is, IV, NV, PV, PVIV, PVNV or PVMG). This includes all numbers, integers and floats, strings, and dualvars containing multiple parts. she contains multitudes π
uv
$uv = $sv->uv;
Returns the integer numeric portion as an unsigned value, if valid, or undef.
iv
$iv = $sv->iv;
Returns the integer numeric portion as a signed value, if valid, or undef.
nv
$nv = $sv->nv;
Returns the floating numeric portion, if valid, or undef.
pv
$pv = $sv->pv;
Returns the string portion, if valid, or undef.
pvlen
$pvlen = $sv->pvlen;
Returns the length of the string portion, if valid, or undef.
qq_pv
$str = $sv->qq_pv( $maxlen );
Returns the PV string, if defined, suitably quoted. And if $maxlen is defined and the PV is longer than that? it gets truncated and ... gets appended after the containing quote marks. βοΈ
ourstash
$stash = $sv->ourstash;
Returns the stash of the SCALAR, if it's an "our" variable.
π After perl 5.20 this is no longer used, and will return undef. rip to a real one.
π Devel::MAT::SV::REF π
Represents a referential scalar β any SCALAR-type SV with the SvROK flag set.
rv
$svrv = $sv->rv;
Returns the SV referred to by the reference.
is_weak
$weak = $sv->is_weak;
Returns true if the SV is a weakened RV reference.
ourstash
$stash = $sv->ourstash;
Returns the stash of the SCALAR, if it's an "our" variable.
π Devel::MAT::SV::ARRAY π
Represents an array β an SV of type SVt_PVAV.
is_unreal
$unreal = $av->is_unreal;
Returns true if the AvREAL() flag is not set on the array β i.e. that its SV pointers do not contribute to the SvREFCNT of the SVs it points at. unreal, literally.
is_backrefs
$backrefs = $av->is_backrefs;
Returns true if the array contains the backrefs list of a hash or weakly-referenced object.
elems
@svs = $av->elems;
Returns all of the element SVs, in a list. the whole squad. π«Ά
elem
$sv = $av->elem( $index );
Returns the SV at the given index.
π§ Devel::MAT::SV::PADLIST π§
A subclass of ARRAY β this one is used to represent the PADLIST of a CODE SV.
πΈ Devel::MAT::SV::PADNAMES πΈ
A subclass of ARRAY β this one is used to represent the PADNAMES of a CODE SV.
padname
$padname = $padnames->padname( $padix );
Returns the name of the lexical at the given index, or undef.
padix_from_padname
$padix = $padnames->padix_from_padname( $padname );
Returns the index of the lexical with the given name, or undef.
β¨ Devel::MAT::SV::PAD β¨
A subclass of ARRAY β this one is used to represent a PAD of a CODE SV.
padcv
$cv = $pad->padcv;
Returns the CODE SV that this is a pad for.
lexvars
( $name, $sv, $name, $sv, ... ) = $pad->lexvars;
Returns a name/value list of the lexical variables in the pad.
maybe_lexvar
$sv = $pad->maybe_lexvar( $padname );
Since version 0.49.
Returns the SV associated with the given padname if one exists, or undef if not.
Used to be named lexvar. glow up π
π Devel::MAT::SV::HASH π
Represents a hash β an SV of type SVt_PVHV. And heads up: the Devel::MAT::SV::STASH subclass is used to represent hashes that are used as stashes.
keys
@keys = $hv->keys;
Returns the set of keys present in the hash, as plain perl strings, in no particular order. do not count on the order, bestie.
value
$sv = $hv->value( $key );
Returns the SV associated with the given key.
values
@svs = $hv->values;
Returns all of the SVs stored as values, in no particular order (though, in an order corresponding to the order returned by keys).
π Devel::MAT::SV::STASH π
Represents a hash used as a stash β an SV of type SVt_PVHV whose HvNAME() is non-NULL. This is a subclass of Devel::MAT::SV::HASH.
mro_linear_all, mro_linearcurrent, mro_nextmethod, mro_isa
$hv = $stash->mro_linear_all;
$sv = $stash->mro_linearcurrent;
$sv = $stash->mro_nextmethod;
$av = $stash->mro_isa;
Returns the fields from the MRO structure.
value_code
$cv = $stash->value_code( $key );
Returns the CODE associated with the given symbol name, if it exists, or undef if not. This is roughly equivalent to:
$cv = $stash->value( $key )->code;
Except that it's aware of the direct reference to CVs that perl 5.22 will optimise for. so use this method in preference to that construct up there. fr fr.
stashname
$name = $stash->stashname;
Returns the name of the stash.
and bestieβ¦ we are so not done yet. part 2 is right below this, keep scrolling π
πΈ Devel::MAT::SV::CODE πΈ
bestie this one represents a function or a closure β an SV that's type SVt_PVCV. so like, all the actual code π
stash, glob, file, line, scope, padlist, constval, oproot, depth
$stash = $cv->stash;
$gv = $cv->glob;
$filename = $cv->file;
$line = $cv->line;
$scope_cv = $cv->scope;
$av = $cv->padlist;
$sv = $cv->constval;
$addr = $cv->oproot;
$depth = $cv->depth;
these hand you back the code's stash, glob, filename, line number, scope, padlist, constant value, oproot or depth. one stop shop, no cap β¨
location
$location = $cv->location;
gives you "FILE line LINE" when the line is defined, or just "FILE" when it's not. so cute and simple π
is_clone, is_cloned, is_xsub, is_weakoutside, is_cvgv_rc, is_lexical
$clone = $cv->is_clone;
$cloned = $cv->is_cloned;
$xsub = $cv->is_xsub;
$weak = $cv->is_weakoutside;
$rc = $cv->is_cvgv_rc;
$lexical = $cv->is_lexical;
these give you the CvCLONE(), CvCLONED(), CvISXSUB(), CvWEAKOUTSIDE(), CvCVGV_RC() and CvLEXICAL() flags. flag check, vibe check, same thing π
protosub
$protosub = $cv->protosub;
returns the protosub CV, if it's known, for a closure CV. lowkey important for closures bestie π¦
constants
@svs = $cv->constants;
gives you a list of the SVs that get used as constants or method names in the code. heads up tho β on ithreads perl the constants are part of the padlist structure, so this list gets constructed from parts of the padlist at loading time. it's giving β¨assembledβ¨ π
globrefs
@svs = $cv->globrefs;
same deal but for the SVs used as GLOB references in the code. and yes, same caveat: on ithreads perl the constants are part of the padlist structure, so this list is constructed from parts of the padlist at loading time. iykyk π
padname
$padname = $cv->padname( $padix );
returns the name of the $padix'th lexical variable, or undef if it's out here living nameless π
the returned padname is a whole structure with these fields:
$name = $padname->name;
$bool = $padname->is_outer;
$bool = $padname->is_state;
$bool = $padname->is_lvalue;
$bool = $padname->is_typed;
$bool = $padname->is_our;
$bool = $padname->is_field;
padix_from_padname
$padix = $cv->padix_from_padname( $padname );
gives you the index of the first lexical variable with that pad name, or undef if there is no such thing. no variable, no index, periodt π
max_padix
$max_padix = $cv->max_padix;
returns the maximum valid pad index. this is typically how you'd build a list of potential pad indexes, like:
0 .. $cv->max_padix;
but bestie listen β pad slots can hold things that are not lexical variables. so like, not every pad slot between 0 and this index is guaranteed to contain a lexical variable or even have a pad name. don't assume βπ
padnames_av
$padnames_av = $cv->padnames_av;
returns the AV reference directly that stores the pad names.
after perl version 5.20, this is no longer used directly and it will return undef. the individual pad names themselves can still be found via the padname method tho, so we're fine π«Ά
pads
@pads = $cv->pads;
returns a list of the actual pad AVs. all of them. the whole squad π
pad
$pad = $cv->pad( $depth );
returns the PAD at the given depth β and that depth is a 1-based index, so don't come at it with 0 girlie π
maybe_lexvar
$sv = $cv->maybe_lexvar( $padname, $depth );
since version 0.49.
returns the SV on the PAD associated with the given padname, at the optionally-given depth (1-based index). if $depth isn't provided, the topmost live PAD gets used. and if no variable exists with that given name, you get undef. no variable, no drama πΈ
used to be called lexvar. glow-up name change, we love to see it β¨
π Devel::MAT::SV::IO π
represents an IO handle β an SV type of SVt_PVIO. the plumbing, the vibes π
ifileno, ofileno
$ifileno = $io->ifileno;
$ofileno = $io->ofileno;
returns the input or output file numbers. in and out, that's the whole personality π
π Devel::MAT::SV::OBJECT π
represents an object instance β an SV of type SVt_PVOBJ.
these are only present in files from perls with feature 'class'. if your perl's not on that wave, bestie they're simply not here π¦
fields
@svs = $obj->fields;
returns all the values of all the fields in a list. everything, all at once, iconic π
note that to find the names of the fields you'll have to enquire with the class. so like, this gives you values, not labels, ok? π£
field
$sv = $obj->field( $name_or_fieldix );
returns the value of the given field β you can specify it by name or by index directly. your choice, main character energy π
π Devel::MAT::SV::CLASS π
represents a class β a sub-type of stash, for implementing object classes.
again, these are only present in files from perls with feature 'class'. no class feature, no class representation, no cap β¨
fields
@fields = $class->fields;
returns a list of the field definitions of the class, in declaration order. each one is a structure whose form is given below. yes bestie, the order is preserved, we stay faithful to the source π
field
$field = $class->field( $name_or_fieldix );
returns the field definition of the given field β by name or by index directly, whatever you vibe with.
β οΈ it throws an exception if none such exists. like, it will be loud about it. no silent undef here π
the returned field is a structure with these fields:
$fieldix = $field->fieldix;
$name = $field->name;
maybe_field
$field = $class->maybe_field( $name_or_fieldix );
since version 0.49.
basically field but gentler β it returns undef if none such exists instead of yelling at you. the soft-launch version π«Ά
πΈ Devel::MAT::SV::C_STRUCT πΈ
represents a C-level struct type. deep in the C layers, but we still look cute down here π
fields
@kvlist = $struct->fields;
returns an even-sized name/value list of all the field values stored by the struct β and each one is preceeded by its field type structure. yes, both. name/value pairs and the type structure. the whole package π
field_named
$val = $struct->field_named( $name );
looks for a field whose name is exactly the one you gave it, and returns its value.
β οΈ throws an exception if the struct has no such field of that name. exact match or nothing, bestie π
maybe_field_named
$val = $struct->maybe_field_named( $name );
since version 0.49.
just like field_named but it returns undef if there's no such field. no exceptions thrown, just chill π
structtype
$structtype = $struct->structtype;
returns a metadata structure describing the type of the struct itself. it has these named accessors:
name=> STRING β the name of the struct type, as given by the dumpfile.fields=> ARRAY[ Field ] β an ARRAY reference containing the definitions of each field in turn.
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> π absolute legend, we stan π«Ά
and that's the whole page bestie! this doc ships as perl v5.42.3, dated 2026-08-21 β so if you're holding an older copy, that's why your page might look a lil different. go read your dumpfiles, you're gonna slay π β¨π
π¦ where this page comes from
- ubuntu stonking: libdevel-mat-perl 0.54-1build1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms