Test2::Util::Sub(3)
π NAME π
okay bestie, this is the manual page for Test2::Util::Sub β that's Test2::Util::Sub(3), a User Contributed Perl Documentation page, and it's literally Tools for inspecting and manipulating subs. No cap. π
β¨ DESCRIPTION β¨
Utilities used by Test2::Tools to inspect and manipulate subroutines. That's the whole vibe: the helper utilities that Test2::Tools uses when it needs to look at subs and do stuff to them. Obsessed. π«Ά
π EXPORTS π
All exports are optional, you must specify subs to import. Like, none of this auto-imports sneakily into your namespace β if you want these, name them. Periodt. π
$name = sub_name(\&sub)
Get the name of the sub. Simple, iconic, does exactly what it says. β¨
my $hr = sub_info(\&code)
This returns a hashref with information about the sub:
{
ref => \&code,
cobj => $cobj,
name => "Some::Mod::code",
file => "Some/Mod.pm",
package => "Some::Mod",
# Note: These have been adjusted based on guesswork.
start_line => 22,
end_line => 42,
lines => [22, 42],
# Not a bug, these lines are different!
all_lines => [23, 25, ..., 39, 41],
};
Here's the breakdown, bestie:
$info->{ref}=>\&codeβ this is the original sub passed tosub_info(). It's the coderef you handed in, no cap. π«Ά$info->{cobj}=>$cobjβ this is the c-object representation of the coderef. Very internal, very iconic. π§$info->{name}=>"Some::Mod::code"β this is the name of the coderef. For anonymous coderefs this may end with__ANON__. Also note that the package'main'is special, and'main::'may be omitted. Iykyk. π$info->{file}=>"Some/Mod.pm"β the file in which the sub was defined. π$info->{package}=>"Some::Mod"β the package in which the sub was defined. Slay. β¨$info->{start_line}=>22,$info->{end_line}=>42,$info->{lines}=>[22, 42]β these three fields are the adjusted start line, end line, and array with both. Important: these lines have been adjusted and may not be accurate. π¨
The lines are obtained by walking the ops. As such, the first line is the line of the first statement, and the last line is the line of the last statement. This means that in multi-line subs the lines are usually off by 1. The lines in these keys will be adjusted for you if it detects a multi-line sub.
$info->{all_lines}=>[23, 25, ..., 39, 41]β this is an array with the lines of every statement in the sub. Unlike the other line fields, these have not been adjusted for you. Lowkey important. π¦
π SOURCE π
The source code repository for Test2-Suite can be found at https://github.com/Test-More/test-more/. Go click, bestie. π
π MAINTAINERS π
Chad Granum <exodist@cpan.org> π
π AUTHORS π
- Chad Granum
<exodist@cpan.org> - Kent Fredric
<kentnl@cpan.org>
π COPYRIGHT π
Copyright Chad Granum <exodist@cpan.org>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
and that's a wrap, bestie β this page comes from perl v5.42.0, dated 2025-07-28, and it's filed as Test2::Util::Sub(3). Slay. π
β¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Test-Simple 1.302214-bp160.1.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms