Server IP : 103.119.228.120 / Your IP : 3.135.200.121 Web Server : Apache System : Linux v8.techscape8.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : nobody ( 99) PHP Version : 5.6.40 Disable Function : shell_exec,symlink,system,exec,proc_get_status,proc_nice,proc_terminate,define_syslog_variables,syslog,openlog,closelog,escapeshellcmd,passthru,ocinum cols,ini_alter,leak,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dl,dll,myshellexec,proc_open,socket_bind,proc_close,escapeshellarg,parse_ini_filepopen,fpassthru,exec,passthru,escapeshellarg,escapeshellcmd,proc_close,proc_open,ini_alter,popen,show_source,proc_nice,proc_terminate,proc_get_status,proc_close,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,dl,symlink,shell_exec,system,dl,passthru,escapeshellarg,escapeshellcmd,myshellexec,c99_buff_prepare,c99_sess_put,fpassthru,getdisfunc,fx29exec,fx29exec2,is_windows,disp_freespace,fx29sh_getupdate,fx29_buff_prepare,fx29_sess_put,fx29shexit,fx29fsearch,fx29ftpbrutecheck,fx29sh_tools,fx29sh_about,milw0rm,imagez,sh_name,myshellexec,checkproxyhost,dosyayicek,c99_buff_prepare,c99_sess_put,c99getsource,c99sh_getupdate,c99fsearch,c99shexit,view_perms,posix_getpwuid,posix_getgrgid,posix_kill,parse_perms,parsesort,view_perms_color,set_encoder_input,ls_setcheckboxall,ls_reverse_all,rsg_read,rsg_glob,selfURL,dispsecinfo,unix2DosTime,addFile,system,get_users,view_size,DirFiles,DirFilesWide,DirPrintHTMLHeaders,GetFilesTotal,GetTitles,GetTimeTotal,GetMatchesCount,GetFileMatchesCount,GetResultFiles,fs_copy_dir,fs_copy_obj,fs_move_dir,fs_move_obj,fs_rmdir,SearchText,getmicrotime MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/local/ssl/local/ssl/local/ssl/local/ssl/local/lib64/perl5/Sub/ |
Upload File : |
package Sub::Identify; use strict; use Exporter; BEGIN { our $VERSION = '0.12'; our @ISA = ('Exporter'); our %EXPORT_TAGS = ( all => [ our @EXPORT_OK = qw( sub_name stash_name sub_fullname get_code_info get_code_location is_sub_constant ) ] ); our $IsPurePerl = 1; unless ($ENV{PERL_SUB_IDENTIFY_PP}) { if ( eval { require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); 1; } ) { $IsPurePerl = 0; } else { die $@ if $@ && $@ !~ /object version|loadable object/; } } if ($IsPurePerl) { require B; *get_code_info = sub ($) { my ($coderef) = @_; ref $coderef or return; my $cv = B::svref_2object($coderef); $cv->isa('B::CV') or return; # bail out if GV is undefined $cv->GV->isa('B::SPECIAL') and return; return ($cv->GV->STASH->NAME, $cv->GV->NAME); }; *get_code_location = sub ($) { my ($coderef) = @_; ref $coderef or return; my $cv = B::svref_2object($coderef); $cv->isa('B::CV') && $cv->START->isa('B::COP') or return; return ($cv->START->file, $cv->START->line); }; } if ($IsPurePerl || $] < 5.016) { require B; *is_sub_constant = sub ($) { my ($coderef) = @_; ref $coderef or return 0; my $cv = B::svref_2object($coderef); $cv->isa('B::CV') or return 0; my $p = prototype $coderef; defined $p && $p eq "" or return 0; return ($cv->CvFLAGS & B::CVf_CONST()) == B::CVf_CONST(); }; } } sub stash_name ($) { (get_code_info($_[0]))[0] } sub sub_name ($) { (get_code_info($_[0]))[1] } sub sub_fullname ($) { join '::', get_code_info($_[0]) } 1; __END__ =head1 NAME Sub::Identify - Retrieve names of code references =head1 SYNOPSIS use Sub::Identify ':all'; my $subname = sub_name( $some_coderef ); my $packagename = stash_name( $some_coderef ); # or, to get all at once... my $fully_qualified_name = sub_fullname( $some_coderef ); defined $subname and say "this coderef points to sub $subname in package $packagename"; my ($file, $line) = get_code_location( $some_coderef ); $file and say "this coderef is defined at line $line in file $file"; is_sub_constant( $some_coderef ) and say "this coderef points to a constant subroutine"; =head1 DESCRIPTION C<Sub::Identify> allows you to retrieve the real name of code references. It provides six functions, all of them taking a code reference. C<sub_name> returns the name of the code reference passed as an argument (or C<__ANON__> if it's an anonymous code reference), C<stash_name> returns its package, and C<sub_fullname> returns the concatenation of the two. C<get_code_info> returns a list of two elements, the package and the subroutine name (in case of you want both and are worried by the speed.) In case of subroutine aliasing, those functions always return the original name. C<get_code_location> returns a two-element list containing the file name and the line number where the subroutine has been defined. C<is_sub_constant> returns a boolean value indicating whether the subroutine is a constant or not. =head2 Pure-Perl version By default C<Sub::Identify> tries to load an XS implementation of the C<get_code_info>, C<get_code_location> and (on perl versions 5.16.0 and later) C<is_sub_constant> functions, for speed; if that fails, or if the environment variable C<PERL_SUB_IDENTIFY_PP> is defined to a true value, it will fall back to a pure perl implementation, that uses perl's introspection mechanism, provided by the C<B> module. =head1 SEE ALSO L<Sub::Util>, part of the module distribution L<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. L<Sub::Name> =head1 SOURCE A git repository for the sources is at L<https://github.com/rgs/Sub-Identify>. =head1 LICENSE (c) Rafael Garcia-Suarez (rgs at consttype dot org) 2005, 2008, 2012, 2014, 2015 This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself. =cut