⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modperl::methodlookup.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.el .IP "arg1: \f(CW$object\fR or \f(CW$class\fR" 4.IX Item "arg1: $object or $class"an object or a name of a class an object is blessed into.SpIf a sub-classed object is passed it'll be handled correctly, byincluding methods provided by its super\-class(es)..ie n .IP "ret1: $hint" 4.el .IP "ret1: \f(CW$hint\fR" 4.IX Item "ret1: $hint"a string containing a human readable lookup result, suggesting, whichmethods the given object can invoke (including module names that needto be loaded to use those methods), or explaining the failure if thelookup failed..ie n .IP "ret2: @methods" 4.el .IP "ret2: \f(CW@methods\fR" 4.IX Item "ret2: @methods"an array of methods which have matched the query, i.e. the names ofthe methods that can be invoked on the given object (or its classname)..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PP\&\s-1META:\s0 As of this writing this function may miss some of thefunctions/methods that can be invoked on the given object. Currentlywe can't programmatically deduct the objects they are invoked on,because these methods are written in pure \s-1XS\s0 and manipulate thearguments stack themselves. Currently these are mainly \s-1XS\s0 functions,not methods, which of course aren't invoked on objects. There are alsologging function wrappers (\f(CW\*(C`Apache2::Log\*(C'\fR)..PPExamples:.PPWhat \s-1XS\s0 methods can be invoked on the object \f(CW$r\fR:.PP.Vb 2\&  my ($hint, @methods) =\&      ModPerl::MethodLookup::lookup_object($r);.Ve.PPor \f(CW$r\fR's class \*(-- \f(CW\*(C`Apache2::RequestRec\*(C'\fR:.PP.Vb 2\&  my ($hint, @methods) =\&      ModPerl::MethodLookup::lookup_object(\*(AqApache2::RequestRec\*(Aq);.Ve.ie n .Sh """preload_all_modules()""".el .Sh "\f(CWpreload_all_modules()\fP".IX Subsection "preload_all_modules()"The function \f(CW\*(C`preload_all_modules()\*(C'\fR preloads all mod_perl 2.0modules, which implement their \s-1API\s0 in \s-1XS\s0. This is similar to themod_perl 1.0 behavior which has most of its methods loaded at thestartup..PP\&\s-1CPAN\s0 modules developers should make sure their distribution loads eachof the used mod_perl 2.0 modules explicitly, and not use thisfunction, as it takes the fine control away from the users. One shouldavoid doing this the production server (unless all modules are usedindeed) in order to save memory..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """print_method()""".el .Sh "\f(CWprint_method()\fP".IX Subsection "print_method()"\&\f(CW\*(C`print_method()\*(C'\fR is a convenience wrapper for\&\f(CW\*(C`lookup_method()\*(C'\fR, mainly designed to be usedfrom the command line. For example to print all the modules whichdefine method \fIread\fR execute:.PP.Vb 1\&  % perl \-MModPerl::MethodLookup \-e print_method read.Ve.PPSince this will return more than one module, we can narrow the queryto only those methods which expect the first argument to be blessedinto class \f(CW\*(C`APR::Bucket\*(C'\fR:.PP.Vb 1\&  % perl \-MModPerl::MethodLookup \-e print_method read APR::Bucket.Ve.PPYou can pass more than one method and it'll perform a lookup on eachof the methods. For example to lookup methods \f(CW\*(C`get_server_built\*(C'\fR and\&\f(CW\*(C`request\*(C'\fR you can do:.PP.Vb 2\&  % perl \-MModPerl::MethodLookup \-e print_method \e\&    get_server_built request.Ve.PPThe function \f(CW\*(C`print_method()\*(C'\fR is exported by default..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """print_module()""".el .Sh "\f(CWprint_module()\fP".IX Subsection "print_module()"\&\f(CW\*(C`print_module()\*(C'\fR is a convenience wrapper for\&\f(CW\*(C`lookup_module()\*(C'\fR, mainly designed to be usedfrom the command line. For example to print all the methods defined inthe module \f(CW\*(C`Apache2::RequestRec\*(C'\fR, followed by methods defined in themodule \f(CW\*(C`Apache2::Filter\*(C'\fR you can run:.PP.Vb 2\&  % perl \-MModPerl::MethodLookup \-e print_module \e\&    Apache2::RequestRec Apache2::Filter.Ve.PPThe function \f(CW\*(C`print_module()\*(C'\fR is exported by default..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """print_object()""".el .Sh "\f(CWprint_object()\fP".IX Subsection "print_object()"\&\f(CW\*(C`print_object()\*(C'\fR is a convenience wrapper for\&\f(CW\*(C`lookup_object()\*(C'\fR, mainly designed to be usedfrom the command line. For example to print all the methods that canbe invoked on object blessed into a class \f(CW\*(C`Apache2::RequestRec\*(C'\fR run:.PP.Vb 2\&  % perl \-MModPerl::MethodLookup \-e print_object \e\&    Apache2::RequestRec.Ve.PPSimilar to \f(CW\*(C`print_object()\*(C'\fR, more than oneclass can be passed to this function..PPThe function \f(CW\*(C`print_object()\*(C'\fR is exported by default..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".SH "Applications".IX Header "Applications".ie n .Sh """AUTOLOAD""".el .Sh "\f(CWAUTOLOAD\fP".IX Subsection "AUTOLOAD"When Perl fails to locate a method it checks whether the package theobject belongs to has an \f(CW\*(C`AUTOLOAD\*(C'\fR function defined and if so, callsit with the same arguments as the missing method while setting aglobal variable \f(CW$AUTOLOAD\fR (in that package) to the name of theoriginally called method. We can use this facility to lookup themodules to be loaded when such a failure occurs. Though since we havemany packages to take care of we will use a special\&\f(CW\*(C`UNIVERSAL::AUTOLOAD\*(C'\fR function which Perl calls if can't find the\&\f(CW\*(C`AUTOLOAD\*(C'\fR function in the given package..PPIn that function you can query \f(CW\*(C`ModPerl::MethodLookup\*(C'\fR, \fIrequire()\fR themodule that includes the called method and call that method againusing the \fIgoto()\fR trick:.PP.Vb 12\&  use ModPerl::MethodLookup;\&  sub UNIVERSAL::AUTOLOAD {\&      my ($hint, @modules) =\&          ModPerl::MethodLookup::lookup_method($UNIVERSAL::AUTOLOAD, @_);\&      if (@modules) {\&          eval "require $_" for @modules;\&          goto &$UNIVERSAL::AUTOLOAD;\&      }\&      else {\&          die $hint;\&      }\&  }.Ve.PPHowever we don't endorse this approach. It's a better approach toalways abort the execution which printing the \f(CW$hint\fRand use fix thecode to load the missing module. Moreover installing\&\f(CW\*(C`UNIVERSAL::AUTOLOAD\*(C'\fR may cause a lot of problems, since once it'sinstalled Perl will call it every time some method is missing(e.g. undefined \f(CW\*(C`DESTROY\*(C'\fR methods). The following approach seems tosomewhat work for me. It installs \f(CW\*(C`UNIVERSAL::AUTOLOAD\*(C'\fR only when thethe child process starts..PP.Vb 3\&  httpd.conf:\&  \-\-\-\-\-\-\-\-\-\-\-\&  PerlChildInitHandler ModPerl::MethodLookupAuto\&\&  startup.pl:\&  \-\-\-\-\-\-\-\-\-\-\-\&  {\&      package ModPerl::MethodLookupAuto;\&      use ModPerl::MethodLookup;\&    \&      use Carp;\&      sub handler {\&    \&          *UNIVERSAL::AUTOLOAD = sub {\&              my $method = $AUTOLOAD;\&              return if $method =~ /DESTROY/; # exclude DESTROY resolving\&    \&              my ($hint, @modules) =\&                  ModPerl::MethodLookup::lookup_method($method, @_);\&              $hint ||= "Can\*(Aqt find method $AUTOLOAD";\&              croak $hint;\&          };\&          return 0;\&      }\&  }.Ve.PPThis example doesn't load the modules for you. It'll print to \s-1STDERR\s0what module should be loaded, when a method from the not-yet-loadedmodule is called..PPA similar technique is used by\&\f(CW\*(C`Apache2::porting\*(C'\fR..PP\&\s-1META:\s0 there is a better version of \s-1AUTOLOAD\s0 discussed on the devlist. Replace the current one with it. (search the archive forEazyLife).Sh "Command Line Lookups".IX Subsection "Command Line Lookups"When a method is used and mod_perl has reported a failure to find it,it's often useful to use the command line query to figure out whichmodule needs to be loaded. For example if when executing:.PP.Vb 1\&  $r\->construct_url();.Ve.PPmod_perl complains:.PP.Vb 2\&  Can\*(Aqt locate object method "construct_url" via package\&  "Apache2::RequestRec" at ....Ve.PPyou can ask \f(CW\*(C`ModPerl::MethodLookup\*(C'\fR for help:.PP.Vb 3\&  % perl \-MModPerl::MethodLookup \-e print_method construct_url\&  To use method \*(Aqconstruct_url\*(Aq add:\&          use Apache2::URI ();.Ve.PPand after copy-n-pasting the use statement in our code, the problemgoes away..PPOne can create a handy alias for this technique. For example, C\-styleshell users can do:.PP.Vb 1\&   % alias lookup "perl \-MModPerl::MethodLookup \-e print_method".Ve.PPFor Bash-style shell users:.PP.Vb 1\&   % alias lookup="perl \-MModPerl::MethodLookup \-e print_method".Ve.PPNow the lookup is even easier:.PP.Vb 3\&  % lookup construct_url\&  to use method \*(Aqconstruct_url\*(Aq add:\&          use Apache2::URI;.Ve.PPSimilar aliases can be provided for\&\f(CW\*(C`print_object()\*(C'\fR and\&\f(CW\*(C`print_module()\*(C'\fR..SH "Todo".IX Header "Todo"These methods aren't yet picked by this module (the extract from themap file):.PP.Vb 3\& modperl_filter_attributes     | MODIFY_CODE_ATTRIBUTES\& modperl_spawn_proc_prog       | spawn_proc_prog\& apr_ipsubnet_create           | new.Ve.PPPlease report to the mod_perl development mailinglist if you find any other missing methods. But remember thatas of this moment the module reports only \s-1XS\s0 functions. In the futurewe may add support for pure perl functions/methods as well..SH "See Also".IX Header "See Also".IP "\(bu" 4the mod_perl 1.0 backward compatibilitydocument.IP "\(bu" 4porting Perl modules.IP "\(bu" 4porting \s-1XS\s0 modules.IP "\(bu" 4\&\f(CW\*(C`Apache2::porting\*(C'\fR.SH "Copyright".IX Header "Copyright"mod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0..SH "Authors".IX Header "Authors"The mod_perl development team and numerouscontributors.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -