perl如何查看某个模块中的函数
1、用perl的debug环境,比如要看Data::Dumper这个模块的函数,
perl -d -e 0
Loading DB routines from perl5db.pl version 1.27
Editor support available.
Enter h or `h h' for help, or `man perldebug' for more help.
main::(-e:1): 0
DB<1> use Data::Dumper
DB<2> S Data::Dumper
Data::Dumper::BEGIN
Data::Dumper::Bless
Data::Dumper::DESTROY
Data::Dumper::Deepcopy
Data::Dumper::Deparse
Data::Dumper::Dump
Data::Dumper::Dumper
Data::Dumper::DumperX
Data::Dumper::Dumpf
Data::Dumper::Dumpp
Data::Dumper::Dumpperl
Data::Dumper::Freezer
Data::Dumper::Indent
Data::Dumper::Maxdepth
Data::Dumper::Names
Data::Dumper::Pad
Data::Dumper::Pair
Data::Dumper::Purity
Data::Dumper::Quotekeys
Data::Dumper::Reset
Data::Dumper::Seen
Data::Dumper::Sortkeys
Data::Dumper::Terse
Data::Dumper::Toaster
Data::Dumper::Useperl
Data::Dumper::Useqq
Data::Dumper::Values
Data::Dumper::Varname
Data::Dumper::_dump
Data::Dumper::_sortkeys
Data::Dumper::new
Data::Dumper::qquote
- 2、如果是oo类的模块,可以用DDP这个模块,可以查看类的继承关系,公共变量,私有变量,公共方法,私有方法等
- 比如:perl -MDDP -e 'use LWP::UserAgent;$ua=new LWP::UserAgent; p $ua'
- LWP::UserAgent {
- Parents LWP::MemberMixin
- Linear @ISA LWP::UserAgent, LWP::MemberMixin
- public methods (46) : add_handler, agent, can (UNIVERSAL), clone, conn_cache, cookie_jar, credentials, default_header, default_headers, DOES (UNIVERSAL), env_proxy, from, get, get_basic_credentials, get_my_handler, handlers, head, isa (UNIVERSAL), is_protocol_supported, local_address, max_redirect, max_size, mirror, new, no_proxy, parse_head, post, prepare_request, progress, protocols_allowed, protocols_forbidden, proxy, redirect_ok, remove_handler, request, requests_redirectable, run_handlers, send_request, set_my_handler, show_progress, simple_request, ssl_opts, timeout, use_alarm, use_eval, VERSION (UNIVERSAL)
- private methods (5) : _agent, _elem (LWP::MemberMixin), _need_proxy, _new_response, _process_colonic_headers
- internals: {
- def_headers => HTTP::Headers,
- handlers => {
- response_header => HTTP::Config
- },
- local_address => undef,
- max_redirect => 7,
- max_size => undef,
- no_proxy => [],
- protocols_allowed => undef,
- protocols_forbidden => undef,
- proxy => {},
- requests_redirectable => [
- [0] "GET",
- [1] "HEAD"
- ],
- show_progress => undef,
- ssl_opts => {
- verify_hostname => 1
- },
- timeout => 180,
- use_eval => 1
- }
- }
- 3、自己做手动分析,模块导入后,自然会在符号表中存入相关的函数,遍历出来就是了:
perl -le 'use Data::Dumper;for (keys %Data::Dumper::){print if defined *{$Data::Dumper::{$_}}{CODE}}'
- 4,源代码搜索:
- vim Carp.pm
- :g/^sub/
复制代码
复制代码