Sub::Util#
📦 std
Names and prototypes of code references: read the name a sub was defined under, give an anonymous sub a name that stack traces, caller and profilers show, and set a sub’s prototype at run time.
This is Sub::Util from Scalar-List-Utils 1.70; Sub/Util.pm is upstream’s, and its three functions are the XS ones of ListUtil.xs.
Synopsis#
use Sub::Util qw(subname set_subname set_prototype);
my $anon = sub { (caller(0))[3] };
print subname($anon), "\n"; # main::__ANON__
my $named = set_subname('My::helper', $anon);
print subname($named), "\n"; # My::helper
print $named->(), "\n"; # caller() sees it: My::helper
set_prototype('$$', $named);
print prototype($named), "\n"; # $$
Differences from upstream#
None: upstream’s own tests of the three functions pass unchanged (t/81-xs-native/List-Util/490-upstream-subname.t, 380-upstream-prototype.t).
Functions#
Names#
subname#
Return the fully qualified name of a subroutine reference.
set_subname#
Assign a name to a subroutine reference in place.
Prototypes#
set_prototype#
Set or clear the prototype on a subroutine reference.