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::MAT itself

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. strong references contribute to the refcount of the referrant; the others don't. strong and weak references are SV addresses found directly within the referring SV structure; indirect and inferred references 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::UNDEF
  • Devel::MAT::SV::YES
  • Devel::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