```{index} single: Sub::Name ``` # Sub::Name ```{pperl-module-badges} Sub::Name ``` Give a sub a name: what `caller`, stack traces and profilers report for it. ## Synopsis ```perl use Sub::Name; my $code = subname 'My::Pkg::handler' => sub { die "oops" }; $code->(); # oops at ... line N. (in My::Pkg::handler) subname 'helper', $code; # an unqualified name goes to the caller's package ``` ## What you get back `subname NAME, CODEREF` renames the sub in place and returns the code reference. A NAME with `::` (or the old `'` separator) puts the sub in that package, creating it; without one it goes to the package of the calling code. Only the sub's own name changes: no symbol table entry is created, so the sub is not callable under its new name. CODEREF can also be a glob or, without `strict refs`, the name of a sub. `subname` is exported by default. This is a native implementation of Sub::Name 0.28's `Name.xs`; its `Sub/Name.pm` is used unchanged. ## Differences from upstream Renaming a sub under the debugger no longer leaks a reference to its `%DB::sub` entry, one per call: `Sub::Util::set_subname`, which perl ships and which was taken from this module, fixed that, and pperl runs that code for both modules (t/81-xs-native/Sub-Name/150-or-better.t). ## Functions ### Names #### [`subname`](Name/subname) Rename a sub in place. ```{toctree} :hidden: :maxdepth: 1 Name/subname ```