1Test2::Util::Sub(3)   User Contributed Perl Documentation  Test2::Util::Sub(3)
2
3
4

NAME

6       Test2::Util::Sub - Tools for inspecting and manipulating subs.
7

DESCRIPTION

9       Utilities used by Test2::Tools to inspect and manipulate subroutines.
10

EXPORTS

12       All exports are optional, you must specify subs to import.
13
14       $name = sub_name(\&sub)
15           Get the name of the sub.
16
17       my $hr = sub_info(\&code)
18           This returns a hashref with information about the sub:
19
20               {
21                   ref        => \&code,
22                   cobj       => $cobj,
23                   name       => "Some::Mod::code",
24                   file       => "Some/Mod.pm",
25                   package    => "Some::Mod",
26
27                   # Note: These have been adjusted based on guesswork.
28                   start_line => 22,
29                   end_line   => 42,
30                   lines      => [22, 42],
31
32                   # Not a bug, these lines are different!
33                   all_lines  => [23, 25, ..., 39, 41],
34               };
35
36           $info->{ref} => \&code
37               This is the original sub passed to "sub_info()".
38
39           $info->{cobj} => $cobj
40               This is the c-object representation of the coderef.
41
42           $info->{name} => "Some::Mod::code"
43               This is the name of the coderef. For anonymous coderefs this
44               may end with '__ANON__'. Also note that the package 'main' is
45               special, and 'main::' may be omitted.
46
47           $info->{file} => "Some/Mod.pm"
48               The file in which the sub was defined.
49
50           $info->{package} => "Some::Mod"
51               The package in which the sub was defined.
52
53           $info->{start_line} => 22
54           $info->{end_line} => 42
55           $info->{lines} => [22, 42]
56               These three fields are the adjusted start line, end line, and
57               array with both.  It is important to note that these lines have
58               been adjusted and may not be accurate.
59
60               The lines are obtained by walking the ops. As such, the first
61               line is the line of the first statement, and the last line is
62               the line of the last statement.  This means that in multi-line
63               subs the lines are usually off by 1.  The lines in these keys
64               will be adjusted for you if it detects a multi-line sub.
65
66           $info->{all_lines} => [23, 25, ..., 39, 41]
67               This is an array with the lines of every statement in the sub.
68               Unlike the other line fields, these have not been adjusted for
69               you.
70

SOURCE

72       The source code repository for Test2-Suite can be found at
73       https://github.com/Test-More/Test2-Suite/.
74

MAINTAINERS

76       Chad Granum <exodist@cpan.org>
77

AUTHORS

79       Chad Granum <exodist@cpan.org>
80       Kent Fredric <kentnl@cpan.org>
81
83       Copyright 2018 Chad Granum <exodist@cpan.org>.
84
85       This program is free software; you can redistribute it and/or modify it
86       under the same terms as Perl itself.
87
88       See http://dev.perl.org/licenses/
89
90
91
92perl v5.32.0                      2020-12-16               Test2::Util::Sub(3)
Impressum