Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sub::Util

Native Rust implementation built into the interpreter. Runtime: P5. See original documentation for the full Perl reference.

Functions

preamble

prototype

Returns the prototype string of the subroutine, or undef if no prototype.

Mirrors Sub::Util.xs XS_Sub__Util_prototype: cv = MUTABLE_CV(SvRV(sv)) if CvPROTO(cv): sv_setpvn(TARG, CvPROTO(cv), CvPROTOLEN(cv)); PUSHTARG else: PUSHs(&PL_sv_undef)

perl5 cv.h:112-118: CvPROTO reads SvPVX_const(sv) when SvPOK(sv). pperl: P5CvBody.prototype is a PV SV, null = no prototype.

set_prototype

Sets (or clears when $proto is undef) the prototype of a subroutine. Returns the same code reference.

Mirrors Sub::Util.xs XS_Sub__Util_set_prototype: if SvOK(proto): cv_ckproto_len_flags + sv_setpvn on CvPROTO else: SvPOK_off(cv); Safefree(SvPVX_mutable(cv)) return the original coderef

pperl: assign/clear P5CvBody.prototype PV SV.

set_subname

Sets the name of the subroutine in-place. Unqualified names are placed in “main::”. Returns the same code reference.

Mirrors Sub::Util.xs XS_Sub__Util_set_subname: qualify $name into pkg + shortname cvgv_set(cv, gv) with a new/found GV under that name return the original coderef

pperl simplification: we store the name string directly as P5CvBody.name, bypassing GV manipulation (which requires full glob assignment support).

subname

Returns the fully qualified name of the subroutine (e.g. “main::foo”), or “ANON” for anonymous subs.

Mirrors Sub::Util.xs XS_Sub__Util_subname: cv = MUTABLE_CV(SvRV(sv)) name = CvNAMED(cv) ? hek_to_sv(CvNAMEHEK(cv)) : sv_from_gv(CvGV(cv))

In pperl: P5CvBody.name is the name PV SV (FQN), null = anonymous.