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

NAME

6       Sub::Identify - Retrieve names of code references
7

SYNOPSIS

9           use Sub::Identify ':all';
10           my $subname = sub_name( $some_coderef );
11           my $packagename = stash_name( $some_coderef );
12           # or, to get all at once...
13           my $fully_qualified_name = sub_fullname( $some_coderef );
14           defined $subname
15               and say "this coderef points to sub $subname in package $packagename";
16           my ($file, $line) = get_code_location( $some_coderef );
17           $file
18               and say "this coderef is defined at line $line in file $file";
19           is_sub_constant( $some_coderef )
20               and say "this coderef points to a constant subroutine";
21

DESCRIPTION

23       "Sub::Identify" allows you to retrieve the real name of code
24       references.
25
26       It provides six functions, all of them taking a code reference.
27
28       "sub_name" returns the name of the code reference passed as an argument
29       (or "__ANON__" if it's an anonymous code reference), "stash_name"
30       returns its package, and "sub_fullname" returns the concatenation of
31       the two.
32
33       "get_code_info" returns a list of two elements, the package and the
34       subroutine name (in case of you want both and are worried by the
35       speed.)
36
37       In case of subroutine aliasing, those functions always return the
38       original name.
39
40       "get_code_location" returns a two-element list containing the file name
41       and the line number where the subroutine has been defined.
42
43       "is_sub_constant" returns a boolean value indicating whether the
44       subroutine is a constant or not.
45
46   Pure-Perl version
47       By default "Sub::Identify" tries to load an XS implementation of the
48       "get_code_info", "get_code_location" and (on perl versions 5.16.0 and
49       later) "is_sub_constant" functions, for speed; if that fails, or if the
50       environment variable "PERL_SUB_IDENTIFY_PP" is defined to a true value,
51       it will fall back to a pure perl implementation, that uses perl's
52       introspection mechanism, provided by the "B" module.
53

SEE ALSO

55       Sub::Util, part of the module distribution Scalar::List::Utils since
56       version 1.40. Since this will be a core module starting with perl
57       5.22.0, it is encouraged to migrate to Sub::Util when possible.
58
59       Sub::Name
60

SOURCE

62       A git repository for the sources is at
63       <https://github.com/rgs/Sub-Identify>.
64

LICENSE

66       (c) Rafael Garcia-Suarez (rgs at consttype dot org) 2005, 2008, 2012,
67       2014, 2015
68
69       This program is free software; you may redistribute it and/or modify it
70       under the same terms as Perl itself.
71
72
73
74perl v5.30.0                      2019-07-26                  Sub::Identify(3)
Impressum