B
Native Rust implementation built into the interpreter. Runtime: PP. See original documentation for the full Perl reference.
Native implementation of the B module (Perl compiler backend)
Provides introspection into Perl’s internal representation of code. Supports svref_2object for all SV types (IV, NV, PV, CV, GV, AV, HV, NULL), class(), ppname(), opnumber(), special SVs, utility functions, and basic op tree introspection via B::CV::ROOT/START.
Functions
AV
CUR
CV
CvFLAGS
DEPTH
EGV
FILE
FLAGS
GV
GvREFCNT
HV
IV
IVX
LEN
LINE
NAME
NAME_HEK
NV
NVX
OUTSIDE
PADLIST
PV
PVX
REFCNT
ROOT
SAFENAME
START
STASH
SV
SvTYPE
UVX
amagic_generation
Returns the current overload magic generation counter (always 0 in pperl).
use B qw(amagic_generation);
my $gen = amagic_generation();
See also: sv_undef
can
cast_I32
cast_i32
Casts a value to a signed 32-bit integer, truncating as needed.
use B qw(cast_I32);
my $i = cast_I32(0xFFFFFFFF); # -1
See also: hash
children
class
Returns the B:: class name of a B object (e.g. “CV”, “GV”, “SV”).
use B qw(class);
my $type = class($b_obj);
See also: svref_2object
cop_file
Returns the filename recorded in this COP (control op).
use B qw(main_root);
# walk to a COP node, then:
my $file = $cop->file;
See also: B::COP::line, B::COP::stash
cop_label
Returns the label associated with this COP (e.g. loop labels like “LOOP:”).
use B qw(main_root);
my $label = $cop->label;
See also: B::COP::file, B::COP::line
cop_line
Returns the line number recorded in this COP.
use B qw(main_root);
my $line = $cop->line;
See also: B::COP::file, B::COP::stash
cop_stash
Returns the stash (package) active at this COP as a B::HV object.
use B qw(main_root);
my $stash = $cop->stash;
See also: B::COP::stashpv, B::COP::file
cop_stashpv
Returns the stash name as a plain string (e.g. “main”).
use B qw(main_root);
my $pkg = $cop->stashpv;
See also: B::COP::stash, B::COP::file
cstring
Returns the C-escaped double-quoted representation of a string.
use B qw(cstring);
my $c = cstring("hello\nworld"); # "hello\\nworld"
See also: perlstring
cv_cvflags
Returns the CV flags bitmask (always 0 in pperl).
use B qw(svref_2object);
my $flags = svref_2object(\&foo)->CvFLAGS;
See also: B::CV::DEPTH, B::SV::FLAGS
cv_depth
Returns the recursion depth of this CV (always 0 in pperl).
use B qw(svref_2object);
my $depth = svref_2object(\&foo)->DEPTH;
See also: B::CV::CvFLAGS
cv_file
Returns the filename where this CV was defined.
use B qw(svref_2object);
my $file = svref_2object(\&foo)->FILE;
See also: B::CV::GV, B::CV::START
cv_gv
Returns the GV (glob value) associated with this CV as a B::GV object.
use B qw(svref_2object);
my $gv = svref_2object(\&foo)->GV;
See also: B::GV::NAME, B::CV::FILE
cv_name_hek
Returns the name of the CV from its HEK (hash entry key), or undef for anonymous/global subs.
use B qw(svref_2object);
my $name = svref_2object(\&foo)->NAME_HEK;
See also: B::CV::GV, B::GV::NAME
cv_outside
Returns the lexically enclosing CV as a B::CV object.
use B qw(svref_2object);
my $outer = svref_2object(\&foo)->OUTSIDE;
See also: B::CV::ROOT, B::CV::PADLIST
cv_padlist
Returns the padlist for this CV (currently undef in pperl).
use B qw(svref_2object);
my $padlist = svref_2object(\&foo)->PADLIST;
See also: B::CV::OUTSIDE, B::CV::DEPTH
cv_root
Returns the root op of this CV’s op tree as a B::OP object.
use B qw(svref_2object);
my $root = svref_2object(\&foo)->ROOT;
See also: B::CV::START, B::CV::GV
cv_start
Returns the first op in execution order for this CV as a B::OP object.
use B qw(svref_2object);
my $start = svref_2object(\&foo)->START;
See also: B::CV::ROOT, B::CV::GV
cv_stash
Returns the stash (package hash) associated with this CV as a B::HV object.
use B qw(svref_2object);
my $stash = svref_2object(\&foo)->STASH;
See also: B::CV::GV, B::HV::NAME
desc
file
first
flags
generic_isa
Checks whether a B object is a member of the given class via the @ISA chain.
use B qw(svref_2object);
if (svref_2object(\&foo)->isa("B::CV")) { ... }
See also: class, svref_2object
gv_av
Returns the array slot of this GV as a B::AV object.
use B qw(svref_2object);
my $av = svref_2object(\*foo)->AV;
See also: B::GV::SV, B::GV::HV, B::GV::CV
gv_cv
Returns the code slot of this GV as a B::CV object.
use B qw(svref_2object);
my $cv = svref_2object(\*foo)->CV;
See also: B::GV::SV, B::GV::AV, B::GV::HV
gv_egv
Returns the effective GV (usually the same as the GV itself).
use B qw(svref_2object);
my $egv = svref_2object(\*foo)->EGV;
See also: B::GV::NAME, B::GV::STASH
gv_file
Returns the filename where this GV was first defined.
use B qw(svref_2object);
my $file = svref_2object(\*foo)->FILE;
See also: B::GV::LINE, B::GV::NAME
gv_hv
Returns the hash slot of this GV as a B::HV object.
use B qw(svref_2object);
my $hv = svref_2object(\*foo)->HV;
See also: B::GV::SV, B::GV::AV, B::GV::CV
gv_is_empty
Returns whether this GV is empty (has no assigned slots).
use B qw(svref_2object);
my $empty = svref_2object(\*foo)->is_empty;
See also: B::GV::isGV_with_GP, B::GV::NAME
gv_isgv_with_gp
Returns true if this GV has a GP (glob pointer) structure (always 1 in pperl).
use B qw(svref_2object);
my $has_gp = svref_2object(\*foo)->isGV_with_GP;
See also: B::GV::NAME, B::GV::is_empty
gv_line
Returns the line number where this GV was first defined (always 0 in pperl).
use B qw(svref_2object);
my $line = svref_2object(\*foo)->LINE;
See also: B::GV::FILE, B::GV::NAME
gv_name
Returns the name of this GV (glob value), e.g. “foo” for *main::foo.
use B qw(svref_2object);
my $name = svref_2object(\*foo)->NAME;
See also: B::GV::SAFENAME, B::GV::STASH
gv_refcnt
Returns the GV-specific reference count (always 1 in pperl).
use B qw(svref_2object);
my $rc = svref_2object(\*foo)->GvREFCNT;
See also: B::SV::REFCNT, B::GV::NAME
gv_safename
Returns the name of this GV with control characters converted to ^X notation.
use B qw(svref_2object);
my $safe = svref_2object(\*foo)->SAFENAME;
See also: B::GV::NAME, safename
gv_stash
Returns the stash (package) this GV belongs to as a B::HV object.
use B qw(svref_2object);
my $stash = svref_2object(\*foo)->STASH;
See also: B::GV::NAME, B::HV::NAME
gv_sv
Returns the scalar slot of this GV as a B::SV object.
use B qw(svref_2object);
my $sv = svref_2object(\*foo)->SV;
See also: B::GV::AV, B::GV::HV, B::GV::CV
hash
Returns the hash value of a string as a hex string (e.g. “0x1a2b3c”).
use B qw(hash);
my $h = hash("foo");
See also: cstring, perlstring
hv_name
Returns the name of this HV (stash name), e.g. “main” for %main::.
use B qw(svref_2object);
my $name = svref_2object(\%Foo::)->NAME;
See also: B::GV::STASH, B::CV::STASH
import
Handles use B qw(...) by exporting requested functions into the caller’s namespace.
use B qw(svref_2object class ppname);
See also: svref_2object, class, ppname
int_value
isGV_with_GP
is_empty
isa
iv_iv
Returns the integer value stored in this B::IV object.
use B qw(svref_2object);
my $val = svref_2object(\$n)->IV;
See also: B::IV::UVX, B::NV::NV
iv_uvx
Returns the unsigned integer interpretation of this B::IV object’s value.
use B qw(svref_2object);
my $uval = svref_2object(\$n)->UVX;
See also: B::IV::IV, B::NV::NV
label
last
line
main_cv
Returns the main program’s CV (code value) as a B::CV object.
use B qw(main_cv);
my $cv = main_cv();
See also: main_root, main_start
main_root
Returns the root op of the main program as a B::OP object.
use B qw(main_root);
my $root = main_root();
See also: main_start, main_cv
main_start
Returns the starting op of the main program as a B::OP object.
use B qw(main_start);
my $start = main_start();
moresib
name
next
nv_nv
Returns the floating-point value stored in this B::NV object.
use B qw(svref_2object);
my $val = svref_2object(\$f)->NV;
See also: B::IV::IV, B::PV::PV
object_2svref
op_can
Returns true if the B::OP object supports the named method.
use B qw(main_root);
if (main_root()->can("first")) { ... }
See also: B::OP::isa, B::OP::name
op_children
Returns the number of child ops by walking the first->sibling chain.
use B qw(main_root);
my $count = main_root()->children;
See also: B::OP::first, B::OP::last, B::OP::sibling
op_desc
Returns a human-readable description of this op.
use B qw(main_root);
my $desc = main_root()->desc;
See also: B::OP::name, B::OP::type
op_first
Returns the first child op of a UNOP/BINOP/LISTOP as a B::OP object.
use B qw(main_root);
my $first = main_root()->first;
See also: B::OP::last, B::OP::sibling
op_flags
Returns the op_flags bitmask for this op (OPf_WANT, OPf_KIDS, etc.).
use B qw(main_root);
my $flags = main_root()->flags;
See also: B::OP::private, B::OP::targ
op_last
Returns the last child op of a BINOP/LISTOP as a B::OP object.
use B qw(main_root);
my $last = main_root()->last;
See also: B::OP::first, B::OP::children
op_moresib
Returns true (1) if this op has more siblings, false (0) otherwise.
use B qw(main_root);
my $has_sib = main_root()->first->moresib;
See also: B::OP::sibling, B::OP::children
op_name
Returns the name of this op (e.g. “add”, “const”, “null”).
use B qw(main_root);
my $name = main_root()->name;
See also: B::OP::type, B::OP::desc
op_next
Returns the next op in execution order as a B::OP object.
use B qw(main_start);
my $next = main_start()->next;
See also: B::OP::sibling, B::OP::first
op_opt
Returns whether this op has been optimized (always 0 in pperl).
use B qw(main_root);
my $optimized = main_root()->opt;
See also: B::OP::flags, B::OP::name
op_parent
Returns the parent op in the op tree (always B::NULL in pperl, parent tracking not implemented).
use B qw(main_root);
my $parent = main_root()->first->parent;
See also: B::OP::first, B::OP::sibling
op_ppaddr
Returns the pp function address as a string like “PL_ppaddr[OP_ADD]”.
use B qw(main_root);
my $addr = main_root()->ppaddr;
See also: B::OP::name, ppname
op_private
Returns the op_private flags byte for this op.
use B qw(main_root);
my $priv = main_root()->private;
See also: B::OP::flags, B::OP::targ
op_sibling
Returns the next sibling op in the op tree as a B::OP object.
use B qw(main_root);
my $sib = main_root()->first->sibling;
See also: B::OP::next, B::OP::moresib
op_targ
Returns the op_targ pad offset for this op.
use B qw(main_root);
my $targ = main_root()->targ;
See also: B::OP::flags, B::OP::private
op_type
Returns the numeric op type for this op.
use B qw(main_root);
my $type = main_root()->type;
See also: B::OP::name, B::OP::desc
opnumber
Returns the op number for a given op name (e.g. “add” returns 42).
use B qw(opnumber);
my $num = opnumber("add");
See also: ppname
opt
parent
parents
Returns the parent ops collected during the last walkoptree traversal (currently always empty).
use B qw(parents);
my @parents = parents();
See also: walkoptree, walkoptree_debug
perlstring
Returns the Perl-escaped double-quoted representation of a string, escaping $, @, and using \x{} notation.
use B qw(perlstring);
my $p = perlstring('$foo'); # "\\$foo"
See also: cstring
ppaddr
ppname
Returns the PP function name for a given op number (e.g. “pp_add”).
use B qw(ppname);
my $name = ppname(42);
See also: opnumber
private
pv_cur
Returns the current length (SvCUR) of the string in this B::PV object.
use B qw(svref_2object);
my $len = svref_2object(\$s)->CUR;
See also: B::PV::PV, B::PV::LEN
pv_len
Returns the allocated buffer length (SvLEN) of this B::PV object.
use B qw(svref_2object);
my $alloc = svref_2object(\$s)->LEN;
See also: B::PV::PV, B::PV::CUR
pv_pv
Returns the string value stored in this B::PV object.
use B qw(svref_2object);
my $str = svref_2object(\$s)->PV;
See also: B::PV::CUR, B::PV::LEN
safename
Converts control characters in a name to ^X notation for safe display.
use B qw(safename);
my $safe = safename("\x01foo"); # "^Afoo"
See also: cstring, perlstring
sibling
stash
stashpv
sv_flags
Returns the SV flags bitmask (IOK, NOK, POK, etc.).
use B qw(svref_2object);
my $flags = svref_2object(\$x)->FLAGS;
See also: B::SV::REFCNT, B::SV::SvTYPE
sv_no
Returns a B::SPECIAL object representing PL_sv_no.
use B qw(sv_no);
my $no = sv_no();
sv_object_2svref
Converts a B object back to a reference to the original Perl value.
use B qw(svref_2object);
my $ref = svref_2object(\$x)->object_2svref;
See also: svref_2object
sv_refcnt
Returns the reference count of this SV.
use B qw(svref_2object);
my $rc = svref_2object(\$x)->REFCNT;
See also: B::SV::FLAGS, B::SV::SvTYPE
sv_svtype
Returns the SV type number (SVt_NULL=0, SVt_IV=1, SVt_NV=2, SVt_PV=4, etc.).
use B qw(svref_2object);
my $type = svref_2object(\$x)->SvTYPE;
See also: B::SV::FLAGS, B::SV::REFCNT
sv_undef
Returns a B::SPECIAL object representing PL_sv_undef.
use B qw(sv_undef);
my $undef = sv_undef();
sv_yes
Returns a B::SPECIAL object representing PL_sv_yes.
use B qw(sv_yes);
my $yes = sv_yes();
svref_2object
Converts a Perl reference to its corresponding B:: object representation.
use B qw(svref_2object);
my $b_obj = svref_2object(\$scalar);
See also: class, sv_undef, sv_yes, sv_no
targ
type
walkoptree
Walks the op tree starting from $op, calling $op->$method() on each node in tree order.
use B qw(walkoptree main_root);
walkoptree(main_root(), "print_name");
See also: walkoptree_debug, parents, main_root
walkoptree_debug
Gets or sets the debug flag for walkoptree output.
use B qw(walkoptree_debug);
walkoptree_debug(1);
my $dbg = walkoptree_debug();
See also: walkoptree