.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Test2::Util::Sub 3perl" .TH Test2::Util::Sub 3perl 2024-09-01 "perl v5.40.0" "Perl Programmers Reference Guide" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Test2::Util::Sub \- Tools for inspecting and manipulating subs. .SH DESCRIPTION .IX Header "DESCRIPTION" Utilities used by Test2::Tools to inspect and manipulate subroutines. .SH EXPORTS .IX Header "EXPORTS" All exports are optional, you must specify subs to import. .ie n .IP "$name = sub_name(\e&sub)" 4 .el .IP "\f(CW$name\fR = sub_name(\e&sub)" 4 .IX Item "$name = sub_name(&sub)" Get the name of the sub. .ie n .IP "my $hr = sub_info(\e&code)" 4 .el .IP "my \f(CW$hr\fR = sub_info(\e&code)" 4 .IX Item "my $hr = sub_info(&code)" This returns a hashref with information about the sub: .Sp .Vb 6 \& { \& ref => \e&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], \& }; .Ve .RS 4 .ie n .IP "$info\->{ref} => \e&code" 4 .el .IP "\f(CW$info\fR\->{ref} => \e&code" 4 .IX Item "$info->{ref} => &code" This is the original sub passed to \f(CWsub_info()\fR. .ie n .IP "$info\->{cobj} => $cobj" 4 .el .IP "\f(CW$info\fR\->{cobj} => \f(CW$cobj\fR" 4 .IX Item "$info->{cobj} => $cobj" This is the c\-object representation of the coderef. .ie n .IP "$info\->{name} => ""Some::Mod::code""" 4 .el .IP "\f(CW$info\fR\->{name} => ""Some::Mod::code""" 4 .IX Item "$info->{name} => ""Some::Mod::code""" This is the name of the coderef. For anonymous coderefs this may end with \&\f(CW\*(Aq_\|_ANON_\|_\*(Aq\fR. Also note that the package 'main' is special, and 'main::' may be omitted. .ie n .IP "$info\->{file} => ""Some/Mod.pm""" 4 .el .IP "\f(CW$info\fR\->{file} => ""Some/Mod.pm""" 4 .IX Item "$info->{file} => ""Some/Mod.pm""" The file in which the sub was defined. .ie n .IP "$info\->{package} => ""Some::Mod""" 4 .el .IP "\f(CW$info\fR\->{package} => ""Some::Mod""" 4 .IX Item "$info->{package} => ""Some::Mod""" The package in which the sub was defined. .ie n .IP "$info\->{start_line} => 22" 4 .el .IP "\f(CW$info\fR\->{start_line} => 22" 4 .IX Item "$info->{start_line} => 22" .PD 0 .ie n .IP "$info\->{end_line} => 42" 4 .el .IP "\f(CW$info\fR\->{end_line} => 42" 4 .IX Item "$info->{end_line} => 42" .ie n .IP "$info\->{lines} => [22, 42]" 4 .el .IP "\f(CW$info\fR\->{lines} => [22, 42]" 4 .IX Item "$info->{lines} => [22, 42]" .PD These three fields are the \fIadjusted\fR start line, end line, and array with both. It is important to note that these lines have been adjusted and may not be accurate. .Sp 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. .ie n .IP "$info\->{all_lines} => [23, 25, ..., 39, 41]" 4 .el .IP "\f(CW$info\fR\->{all_lines} => [23, 25, ..., 39, 41]" 4 .IX Item "$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. .RE .RS 4 .RE .SH SOURCE .IX Header "SOURCE" The source code repository for Test2\-Suite can be found at \&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. .SH MAINTAINERS .IX Header "MAINTAINERS" .IP "Chad Granum " 4 .IX Item "Chad Granum " .SH AUTHORS .IX Header "AUTHORS" .PD 0 .IP "Chad Granum " 4 .IX Item "Chad Granum " .IP "Kent Fredric " 4 .IX Item "Kent Fredric " .PD .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright 2018 Chad Granum . .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See \fIhttp://dev.perl.org/licenses/\fR