Manual Pages for UNIX Darwin command on man ModPerl::MethodLookup
MyWebUniversity

Manual Pages for UNIX Darwin command on man ModPerl::MethodLookup

apaacphaechmeodmopderple-r1l0-11.011~.2U1:s~:e2mr:o:dCmoopndetrrplie-br2ul.t-0e2.d.20:P.:e2dr:ol:cdsDo:oc:csau:pm:iea:np:tiMa:ot:diMPooendrPle:r:lM:e:tMheotdhLoodoLkouopk(u3p)(3)

NAME

ModPerl::MethodLookup - Lookup modperl modules, objects and methods

SSyynnooppssiiss

use ModPerl::MethodLookup;

# return all module names containing XS method 'print'

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print');

# return only module names containing method 'print' which

# expects the first argument to be of type 'Apache2::Filter'

# (here $filter is an Apache2::Filter object)

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print', $filter);

# or

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print', 'Apache2::Filter');

# what XS methods defined by module 'Apache2::Filter'

my ($hint, @methods) =

ModPerl::MethodLookup::lookupmodule('Apache2::Filter');

# what XS methods can be invoked on the object $r (or a ref)

my ($hint, @methods) =

ModPerl::MethodLookup::lookupobject($r);

# or

my ($hint, @methods) =

ModPerl::MethodLookup::lookupobject('Apache2::RequestRec');

# preload all mp2 modules in startup.pl

ModPerl::MethodLookup::preloadallmodules();

# command line shortcuts

% perl -MModPerl::MethodLookup -e printmodule \

Apache2::RequestRec Apache2::Filter

% perl -MModPerl::MethodLookup -e printobject Apache2

% perl -MModPerl::MethodLookup -e printmethod \

getserverbuilt request

% perl -MModPerl::MethodLookup -e printmethod read

% perl -MModPerl::MethodLookup -e printmethod read APR::Bucket

DDeessccrriippttiioonn modperl 2.0 provides many methods, which reside in various modules. One has to load each of the modules before using the desired methods.

"ModPerl::MethodLookup" provides the Perl API for finding module names

which contain methods in question and other helper functions, to find out out what methods defined by some module, what methods can be called on a given object, etc. AAPPII ""llooookkuuppmmeetthhoodd(())"" Find modules (packages) containing a certain method

($hint, @modules) = lookupmethod($methodname);

($hint, @modules) = lookupmethod($methodname, $object);

($hint, @modules) = lookupmethod($methodname, $class));

arg1: $methodname ( string )

the method name to look up

opt arg2: $object or $class

a blessed object or the name of the class it's blessed into. If there is more than one match, this extra information is used to return only modules containing methods operating on the objects of the same kind.

If a sub-classed object is passed it'll be handled correctly, by

checking its super-class(es). This usage is useful when the

"AUTOLOAD" is used to find a not yet loaded module which include the called method.

ret1: $hint

a string containing a human readable lookup result, suggesting

which modules should be loaded, ready for copy-n-paste or

explaining the failure if the lookup didn't succeed. ret2: @modules an array of modules which have matched the query, i.e. the names of the modules which contain the requested method. since: 2.0.00 Examples: Return all module names containing XS method print:

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print');

Return only module names containing method print which expects the first argument to be of type "Apache2::Filter":

my $filter = bless {}, 'Apache2::Filter';

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print', $filter);

or:

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod('print', 'Apache2::Filter');

""llooookkuuppmmoodduullee(())"" Find methods contained in a certain module (package)

($hint, @methods) = lookupmodule($modulename);

arg1: $modulename ( string )

the module name

ret1: $hint

a string containing a human readable lookup result, suggesting,

which methods the module $modulename implements, or explaining the

failure if the lookup failed. ret2: @methods an array of methods which have matched the query, i.e. the names of the methods defined in the requested module. since: 2.0.00 Example: What XS methods defined by module "Apache2::Filter":

my ($hint, @methods) =

ModPerl::MethodLookup::lookupmodule('Apache2::Filter');

""llooookkuuppoobbjjeecctt(())""

($hint, @methods) = lookupobject($object);

($hint, @methods) = lookupobject($class);

arg1: $object or $class

an object or a name of a class an object is blessed into

If a sub-classed object is passed it'll be handled correctly, by

including methods provided by its super-class(es).

ret1: $hint

a string containing a human readable lookup result, suggesting, which methods the given object can invoke (including module names that need to be loaded to use those methods), or explaining the failure if the lookup failed. ret2: @methods an array of methods which have matched the query, i.e. the names of the methods that can be invoked on the given object (or its class name). since: 2.0.00 META: As of this writing this function may miss some of the functions/methods that can be invoked on the given object. Currently we can't programmatically deduct the objects they are invoked on, because these methods are written in pure XS and manipulate the arguments stack themselves. Currently these are mainly XS functions, not methods, which of course aren't invoked on objects. There are also logging function wrappers ("Apache2::Log"). Examples:

What XS methods can be invoked on the object $r:

my ($hint, @methods) =

ModPerl::MethodLookup::lookupobject($r);

or $r's class - "Apache2::RequestRec":

my ($hint, @methods) =

ModPerl::MethodLookup::lookupobject('Apache2::RequestRec');

""pprreellooaaddaallllmmoodduulleess(())"" The function "preloadallmodules()" preloads all modperl 2.0 modules, which implement their API in XS. This is similar to the modperl 1.0 behavior which has most of its methods loaded at the startup. CPAN modules developers should make sure their distribution loads each of the used modperl 2.0 modules explicitly, and not use this function, as it takes the fine control away from the users. One should avoid doing this the production server (unless all modules are used indeed) in order to save memory. since: 2.0.00 ""pprriinnttmmeetthhoodd(())"" "printmethod()" is a convenience wrapper for "lookupmethod()", mainly designed to be used from the command line. For example to print all the modules which define method read execute:

% perl -MModPerl::MethodLookup -e printmethod read

Since this will return more than one module, we can narrow the query to only those methods which expect the first argument to be blessed into class "APR::Bucket":

% perl -MModPerl::MethodLookup -e printmethod read APR::Bucket

You can pass more than one method and it'll perform a lookup on each of the methods. For example to lookup methods "getserverbuilt" and "request" you can do:

% perl -MModPerl::MethodLookup -e printmethod \

getserverbuilt request The function "printmethod()" is exported by default. since: 2.0.00 ""pprriinnttmmoodduullee(())"" "printmodule()" is a convenience wrapper for "lookupmodule()", mainly designed to be used from the command line. For example to print all the methods defined in the module "Apache2::RequestRec", followed by methods defined in the module "Apache2::Filter" you can run:

% perl -MModPerl::MethodLookup -e printmodule \

Apache2::RequestRec Apache2::Filter The function "printmodule()" is exported by default. since: 2.0.00 ""pprriinnttoobbjjeecctt(())"" "printobject()" is a convenience wrapper for "lookupobject()", mainly designed to be used from the command line. For example to print all the methods that can be invoked on object blessed into a class "Apache2::RequestRec" run:

% perl -MModPerl::MethodLookup -e printobject \

Apache2::RequestRec Similar to "printobject()", more than one class can be passed to this function. The function "printobject()" is exported by default. since: 2.0.00 AApppplliiccaattiioonnss ""AAUUTTOOLLOOAADD"" When Perl fails to locate a method it checks whether the package the object belongs to has an "AUTOLOAD" function defined and if so, calls it with the same arguments as the missing method while setting a global

variable $AUTOLOAD (in that package) to the name of the originally

called method. We can use this facility to lookup the modules to be loaded when such a failure occurs. Though since we have many packages to take care of we will use a special "UNIVERSAL::AUTOLOAD" function which Perl calls if can't find the "AUTOLOAD" function in the given package.

In that function you can query "ModPerl::MethodLookup", require() the

module that includes the called method and call that method again using the goto() trick:

use ModPerl::MethodLookup;

sub UNIVERSAL::AUTOLOAD {

my ($hint, @modules) =

ModPerl::MethodLookup::lookupmethod($UNIVERSAL::AUTOLOAD, @);

if (@modules) {

eval "require $" for @modules;

goto &$UNIVERSAL::AUTOLOAD;

} else {

die $hint;

} } However we don't endorse this approach. It's a better approach to

always abort the execution which printing the $hintand use fix the code

to load the missing module. Moreover installing "UNIVERSAL::AUTOLOAD" may cause a lot of problems, since once it's installed Perl will call it every time some method is missing (e.g. undefined "DESTROY" methods). The following approach seems to somewhat work for me. It installs "UNIVERSAL::AUTOLOAD" only when the the child process starts. 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::lookupmethod($method, @);

$hint ||= "Can't find method $AUTOLOAD";

croak $hint;

}; return 0; } } This example doesn't load the modules for you. It'll print to STDERR

what module should be loaded, when a method from the not-yet-loaded

module is called. A similar technique is used by "Apache2::porting". META: there is a better version of AUTOLOAD discussed on the dev list. Replace the current one with it. (search the archive for EazyLife) CCoommmmaanndd LLiinnee LLooookkuuppss When a method is used and modperl has reported a failure to find it, it's often useful to use the command line query to figure out which module needs to be loaded. For example if when executing:

$r->constructurl();

modperl complains: Can't locate object method "constructurl" via package "Apache2::RequestRec" at ...

you can ask "ModPerl::MethodLookup" for help:

% perl -MModPerl::MethodLookup -e printmethod constructurl

To use method 'constructurl' add: use Apache2::URI ();

and after copy-n-pasting the use statement in our code, the problem

goes away.

One can create a handy alias for this technique. For example, C-style

shell users can do:

% alias lookup "perl -MModPerl::MethodLookup -e printmethod"

For Bash-style shell users:

% alias lookup="perl -MModPerl::MethodLookup -e printmethod"

Now the lookup is even easier:

% lookup constructurl

to use method 'constructurl' add: use Apache2::URI; Similar aliases can be provided for "printobject()" and "printmodule()". TTooddoo These methods aren't yet picked by this module (the extract from the map file):

modperlfilterattributes | MODIFYCODEATTRIBUTES

modperlspawnprocprog | spawnprocprog apripsubnetcreate | new Please report to the modperl development mailing list if you find any other missing methods. But remember that as of this moment the module reports only XS functions. In the future we may add support for pure perl functions/methods as well. SSeeee AAllssoo +o the modperl 1.0 backward compatibility document +o porting Perl modules +o porting XS modules +o "Apache2::porting" CCooppyyrriigghhtt modperl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. AAuutthhoorrss The modperl development team and numerous contributors.

peralpavc5h.e8.m8odperl-101.1~2::modper2l0-025.-01.02-:2:0docs::api::ModPerl::MethodLookup(3)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™