{"id":7372,"date":"2022-12-20T19:37:51","date_gmt":"2022-12-20T22:37:51","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/subidentify-man3\/"},"modified":"2022-12-20T19:37:51","modified_gmt":"2022-12-20T22:37:51","slug":"subidentify-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/subidentify-man3\/","title":{"rendered":"Sub::Identify (man3)"},"content":{"rendered":"<h1 align=\"center\">Sub::Identify<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#SOURCE\">SOURCE<\/a><br \/> <a href=\"#LICENSE\">LICENSE<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Sub::Identify \u2212 Retrieve names of code references<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">use Sub::Identify &#8216;:all&#8217;; <br \/> my $subname = sub_name( $some_coderef ); <br \/> my $packagename = stash_name( $some_coderef ); <br \/> # or, to get all at once&#8230; <br \/> my $fully_qualified_name = sub_fullname( $some_coderef ); <br \/> defined $subname <br \/> and say &#8220;this coderef points to sub $subname in package $packagename&#8221;; <br \/> my ($file, $line) = get_code_location( $some_coderef ); <br \/> $file <br \/> and say &#8220;this coderef is defined at line $line in file $file&#8221;; <br \/> is_sub_constant( $some_coderef ) <br \/> and say &#8220;this coderef points to a constant subroutine&#8221;;<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;Sub::Identify&#8221; allows you to retrieve the real name of code references.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">It provides six functions, all of them taking a code reference.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;sub_name&#8221; returns the name of the code reference passed as an argument (or &#8220;__ANON__&#8221; if it\u2019s an anonymous code reference), &#8220;stash_name&#8221; returns its package, and &#8220;sub_fullname&#8221; returns the concatenation of the two.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;get_code_info&#8221; returns a list of two elements, the package and the subroutine name (in case of you want both and are worried by the speed.)<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">In case of subroutine aliasing, those functions always return the original name.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;get_code_location&#8221; returns a two-element list containing the file name and the line number where the subroutine has been defined.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">&#8220;is_sub_constant&#8221; returns a boolean value indicating whether the subroutine is a constant or not.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><b>Pure-Perl version<\/b> <br \/> By default &#8220;Sub::Identify&#8221; tries to load an <small>XS<\/small> implementation of the &#8220;get_code_info&#8221;, &#8220;get_code_location&#8221; and (on perl versions 5.16.0 and later) &#8220;is_sub_constant&#8221; functions, for speed; if that fails, or if the environment variable &#8220;PERL_SUB_IDENTIFY_PP&#8221; is defined to a true value, it will fall back to a pure perl implementation, that uses perl\u2019s introspection mechanism, provided by the &#8220;B&#8221; module.<\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Sub::Util, part of the module distribution Scalar::List::Utils since version 1.40. Since this will be a core module starting with perl 5.22.0, it is encouraged to migrate to Sub::Util when possible.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Sub::Name<\/p>\n<h2>SOURCE <a name=\"SOURCE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">A git repository for the sources is at <https:\/\/github.com\/rgs\/Sub\u2212Identify>.<\/p>\n<h2>LICENSE <a name=\"LICENSE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">(c) Rafael Garcia-Suarez (rgs at consttype dot org) 2005, 2008, 2012, 2014, 2015<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">This program is free software; you may redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  Sub::Identify \u2212 Retrieve names of code references <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3686],"class_list":["post-7372","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-subidentify"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7372","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7372"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7372\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}