| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Test2::Util::Sub 3perl" |
| 58 |
.TH Test2::Util::Sub 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Test2::Util::Sub \- Tools for inspecting and manipulating subs. |
| 65 |
.SH DESCRIPTION |
| 66 |
.IX Header "DESCRIPTION" |
| 67 |
Utilities used by Test2::Tools to inspect and manipulate subroutines. |
| 68 |
.SH EXPORTS |
| 69 |
.IX Header "EXPORTS" |
| 70 |
All exports are optional, you must specify subs to import. |
| 71 |
.ie n .IP "$name = sub_name(\e&sub)" 4 |
| 72 |
.el .IP "\f(CW$name\fR = sub_name(\e&sub)" 4 |
| 73 |
.IX Item "$name = sub_name(&sub)" |
| 74 |
Get the name of the sub. |
| 75 |
.ie n .IP "my $hr = sub_info(\e&code)" 4 |
| 76 |
.el .IP "my \f(CW$hr\fR = sub_info(\e&code)" 4 |
| 77 |
.IX Item "my $hr = sub_info(&code)" |
| 78 |
This returns a hashref with information about the sub: |
| 79 |
.Sp |
| 80 |
.Vb 6 |
| 81 |
\& { |
| 82 |
\& ref => \e&code, |
| 83 |
\& cobj => $cobj, |
| 84 |
\& name => "Some::Mod::code", |
| 85 |
\& file => "Some/Mod.pm", |
| 86 |
\& package => "Some::Mod", |
| 87 |
\& |
| 88 |
\& # Note: These have been adjusted based on guesswork. |
| 89 |
\& start_line => 22, |
| 90 |
\& end_line => 42, |
| 91 |
\& lines => [22, 42], |
| 92 |
\& |
| 93 |
\& # Not a bug, these lines are different! |
| 94 |
\& all_lines => [23, 25, ..., 39, 41], |
| 95 |
\& }; |
| 96 |
.Ve |
| 97 |
.RS 4 |
| 98 |
.ie n .IP "$info\->{ref} => \e&code" 4 |
| 99 |
.el .IP "\f(CW$info\fR\->{ref} => \e&code" 4 |
| 100 |
.IX Item "$info->{ref} => &code" |
| 101 |
This is the original sub passed to \f(CWsub_info()\fR. |
| 102 |
.ie n .IP "$info\->{cobj} => $cobj" 4 |
| 103 |
.el .IP "\f(CW$info\fR\->{cobj} => \f(CW$cobj\fR" 4 |
| 104 |
.IX Item "$info->{cobj} => $cobj" |
| 105 |
This is the c\-object representation of the coderef. |
| 106 |
.ie n .IP "$info\->{name} => ""Some::Mod::code""" 4 |
| 107 |
.el .IP "\f(CW$info\fR\->{name} => ""Some::Mod::code""" 4 |
| 108 |
.IX Item "$info->{name} => ""Some::Mod::code""" |
| 109 |
This is the name of the coderef. For anonymous coderefs this may end with |
| 110 |
\&\f(CW\*(Aq_\|_ANON_\|_\*(Aq\fR. Also note that the package 'main' is special, and 'main::' may |
| 111 |
be omitted. |
| 112 |
.ie n .IP "$info\->{file} => ""Some/Mod.pm""" 4 |
| 113 |
.el .IP "\f(CW$info\fR\->{file} => ""Some/Mod.pm""" 4 |
| 114 |
.IX Item "$info->{file} => ""Some/Mod.pm""" |
| 115 |
The file in which the sub was defined. |
| 116 |
.ie n .IP "$info\->{package} => ""Some::Mod""" 4 |
| 117 |
.el .IP "\f(CW$info\fR\->{package} => ""Some::Mod""" 4 |
| 118 |
.IX Item "$info->{package} => ""Some::Mod""" |
| 119 |
The package in which the sub was defined. |
| 120 |
.ie n .IP "$info\->{start_line} => 22" 4 |
| 121 |
.el .IP "\f(CW$info\fR\->{start_line} => 22" 4 |
| 122 |
.IX Item "$info->{start_line} => 22" |
| 123 |
.PD 0 |
| 124 |
.ie n .IP "$info\->{end_line} => 42" 4 |
| 125 |
.el .IP "\f(CW$info\fR\->{end_line} => 42" 4 |
| 126 |
.IX Item "$info->{end_line} => 42" |
| 127 |
.ie n .IP "$info\->{lines} => [22, 42]" 4 |
| 128 |
.el .IP "\f(CW$info\fR\->{lines} => [22, 42]" 4 |
| 129 |
.IX Item "$info->{lines} => [22, 42]" |
| 130 |
.PD |
| 131 |
These three fields are the \fIadjusted\fR start line, end line, and array with both. |
| 132 |
It is important to note that these lines have been adjusted and may not be |
| 133 |
accurate. |
| 134 |
.Sp |
| 135 |
The lines are obtained by walking the ops. As such, the first line is the line |
| 136 |
of the first statement, and the last line is the line of the last statement. |
| 137 |
This means that in multi-line subs the lines are usually off by 1. The lines |
| 138 |
in these keys will be adjusted for you if it detects a multi-line sub. |
| 139 |
.ie n .IP "$info\->{all_lines} => [23, 25, ..., 39, 41]" 4 |
| 140 |
.el .IP "\f(CW$info\fR\->{all_lines} => [23, 25, ..., 39, 41]" 4 |
| 141 |
.IX Item "$info->{all_lines} => [23, 25, ..., 39, 41]" |
| 142 |
This is an array with the lines of every statement in the sub. Unlike the other |
| 143 |
line fields, these have not been adjusted for you. |
| 144 |
.RE |
| 145 |
.RS 4 |
| 146 |
.RE |
| 147 |
.SH SOURCE |
| 148 |
.IX Header "SOURCE" |
| 149 |
The source code repository for Test2\-Suite can be found at |
| 150 |
\&\fIhttps://github.com/Test\-More/Test2\-Suite/\fR. |
| 151 |
.SH MAINTAINERS |
| 152 |
.IX Header "MAINTAINERS" |
| 153 |
.IP "Chad Granum <[email protected]>" 4 |
| 154 |
.IX Item "Chad Granum <[email protected]>" |
| 155 |
.SH AUTHORS |
| 156 |
.IX Header "AUTHORS" |
| 157 |
.PD 0 |
| 158 |
.IP "Chad Granum <[email protected]>" 4 |
| 159 |
.IX Item "Chad Granum <[email protected]>" |
| 160 |
.IP "Kent Fredric <[email protected]>" 4 |
| 161 |
.IX Item "Kent Fredric <[email protected]>" |
| 162 |
.PD |
| 163 |
.SH COPYRIGHT |
| 164 |
.IX Header "COPYRIGHT" |
| 165 |
Copyright 2018 Chad Granum <[email protected]>. |
| 166 |
.PP |
| 167 |
This program is free software; you can redistribute it and/or |
| 168 |
modify it under the same terms as Perl itself. |
| 169 |
.PP |
| 170 |
See \fIhttp://dev.perl.org/licenses/\fR |