libapa...dLookup(3pm)
π NAME π
ModPerl::MethodLookup β lookup mod_perl modules, objects and methods β¨
okay bestie, this is from libapa...dLookup(3pm), User Contributed Perl Documentation, and it's genuinely iconic, let me tell you everything π«Ά
β¨ SYNOPSIS β¨
use ModPerl::MethodLookup;
# return all module names containing XS method 'print'
my ($hint, @modules) =
ModPerl::MethodLookup::lookup_method('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::lookup_method('print', $filter);
# or
my ($hint, @modules) =
ModPerl::MethodLookup::lookup_method('print', 'Apache2::Filter');
# what XS methods defined by module 'Apache2::Filter'
my ($hint, @methods) =
ModPerl::MethodLookup::lookup_module('Apache2::Filter');
# what XS methods can be invoked on the object $r (or a ref)
my ($hint, @methods) =
ModPerl::MethodLookup::lookup_object($r);
# or
my ($hint, @methods) =
ModPerl::MethodLookup::lookup_object('Apache2::RequestRec');
# preload all mp2 modules in startup.pl
ModPerl::MethodLookup::preload_all_modules();
# command line shortcuts
% perl -MModPerl::MethodLookup -e print_module \
Apache2::RequestRec Apache2::Filter
% perl -MModPerl::MethodLookup -e print_object Apache2
% perl -MModPerl::MethodLookup -e print_method \
get_server_built request
% perl -MModPerl::MethodLookup -e print_method read
% perl -MModPerl::MethodLookup -e print_method read APR::Bucket
πΈ DESCRIPTION πΈ
so mod_perl 2.0 is out here serving so many methods, and they live scattered across a bunch of different modules. the thing is, you gotta load each module before you can use the methods inside it. annoying, right? π©
that's where ModPerl::MethodLookup comes in, and honestly it ate. it gives you a Perl API for:
- finding the module names that contain the methods you're asking about π
- plus other helper functions, so you can figure out which methods a given module defines
- and which methods you can call on a given object
it's giving personal assistant energy, fr fr π
π API π
π lookup_method()
find modules (packages) that contain a certain method π΅οΈ
($hint, @modules) = lookup_method($method_name);
($hint, @modules) = lookup_method($method_name, $object);
($hint, @modules) = lookup_method($method_name, $class));
- arg1:
$method_name( string ) β the method name you wanna look up, bestie - opt arg2:
$objector$classβ a blessed object, or the name of the class it's blessed into. if there's more than one match, this extra lil detail gets used to only hand you back the modules whose methods operate on objects of the same kind. and if you pass a sub-classed object, it gets handled correctly by checking its super-class(es). this usage is the vibe whenAUTOLOADis used to find a not-yet-loaded module that includes the method being called β¨ - ret1:
$hintβ a string with a human readable lookup result, suggesting which modules should get loaded, ready for copy-n-paste π β or explaining the failure if the lookup didn't succeed π - ret2:
@modulesβ an array of modules that matched the query, aka the names of the modules containing the requested method π - since: 2.0.00
π Examples:
return all module names containing XS method print:
my ($hint, @modules) =
ModPerl::MethodLookup::lookup_method('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::lookup_method('print', $filter);
or:
my ($hint, @modules) =
ModPerl::MethodLookup::lookup_method('print', 'Apache2::Filter');
π lookup_module()
find the methods contained in a certain module (package) π¦
($hint, @methods) = lookup_module($module_name);
- arg1:
$module_name( string ) β the module name, periodt - ret1:
$hintβ a string with a human readable lookup result, suggesting which methods the module$module_nameimplements, or explaining the failure if the lookup failed π - ret2:
@methodsβ an array of methods that matched the query, aka 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::lookup_module('Apache2::Filter');
π lookup_object()
($hint, @methods) = lookup_object($object);
($hint, @methods) = lookup_object($class);
- arg1:
$objector$classβ an object, or a name of a class that an object is blessed into. if you pass a sub-classed object it'll be handled correctly, by including the methods provided by its super-class(es) π§ - ret1:
$hintβ a string with 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 that matched the query, aka 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). heads up bestie, it's not perfect π
π Examples:
what XS methods can be invoked on the object $r:
my ($hint, @methods) =
ModPerl::MethodLookup::lookup_object($r);
or $r's class β Apache2::RequestRec:
my ($hint, @methods) =
ModPerl::MethodLookup::lookup_object('Apache2::RequestRec');
β‘ preload_all_modules()
the function preload_all_modules() preloads all mod_perl 2.0 modules that implement their API in XS. this is similar to the mod_perl 1.0 behavior, which had most of its methods loaded at the startup π
CPAN modules developers, listen up: you should make sure your distribution loads each of the used mod_perl 2.0 modules explicitly, and not use this function, because it takes the fine control away from the users π ββοΈ
also you should avoid doing this on the production server (unless all modules are indeed used) in order to save memory. no cap π§
- since: 2.0.00
π¨οΈ print_method()
print_method() is a convenience wrapper for lookup_method(), 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 print_method 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 print_method read APR::Bucket
you can pass more than one method and it'll perform a lookup on each of them π₯ for example, to lookup methods get_server_built and request you can do:
% perl -MModPerl::MethodLookup -e print_method \
get_server_built request
the function print_method() is exported by default π
- since: 2.0.00
π¨οΈ print_module()
print_module() is a convenience wrapper for lookup_module(), mainly designed to be used from the command line π» for example, to print all the methods defined in the module Apache2::RequestRec, followed by the methods defined in the module Apache2::Filter, you can run:
% perl -MModPerl::MethodLookup -e print_module \
Apache2::RequestRec Apache2::Filter
the function print_module() is exported by default β¨
- since: 2.0.00
π¨οΈ print_object()
print_object() is a convenience wrapper for lookup_object(), mainly designed to be used from the command line π» for example, to print all the methods that can be invoked on an object blessed into a class Apache2::RequestRec, run:
% perl -MModPerl::MethodLookup -e print_object \
Apache2::RequestRec
similar to print_object(), more than one class can be passed to this function π―ββοΈ
the function print_object() is exported by default π
- since: 2.0.00
π Applications π
π« AUTOLOAD π«
Okay bestie so picture this: Perl goes looking for a method, and it's not there. What does Perl do? It checks whether the package that the object belongs to has an AUTOLOAD function defined, and if it does, it calls it β with the exact same arguments as the missing method β while setting a global variable $AUTOLOAD (in that package, iykyk) to the name of the method that was originally called. So we can absolutely use this facility to look up which modules need to be loaded when that sad little failure moment happens. But plot twist: since we have so many packages to take care of, we're gonna use a special UNIVERSAL::AUTOLOAD function, which Perl calls when it 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 then call that method again using the goto() trick:
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;
}
}
However. We do not endorse this approach, bestie, no cap. π The better approach is to always abort the execution while printing the $hintand use fix the code to load the missing module. Plus, installing UNIVERSAL::AUTOLOAD may cause a lot of problems, because once it's installed Perl will call it every single time some method is missing (like, say, undefined DESTROY methods β not the vibe). 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::lookup_method($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)
π΅οΈ Command Line Lookups π΅οΈ
So 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 which module needs to be loaded. For example, if when executing:
$r->construct_url();
mod_perl complains:
Can't locate object method "construct_url" via package
"Apache2::RequestRec" at ...
you can ask ModPerl::MethodLookup for help:
% perl -MModPerl::MethodLookup -e print_method construct_url
To use method 'construct_url' add:
use Apache2::URI ();
and after copy-n-pasting the use statement in our code, the problem goes away. Iconic behaviour honestly. β¨
One can create a handy alias for this technique. For example, C-style shell users can do:
% alias lookup "perl -MModPerl::MethodLookup -e print_method"
For Bash-style shell users:
% alias lookup="perl -MModPerl::MethodLookup -e print_method"
Now the lookup is even easier:
% lookup construct_url
to use method 'construct_url' add:
use Apache2::URI;
Similar aliases can be provided for print_object() and print_module().
π Todo π
These methods aren't yet picked by this module (the extract from the map file):
modperl_filter_attributes | MODIFY_CODE_ATTRIBUTES
modperl_spawn_proc_prog | spawn_proc_prog
apr_ipsubnet_create | new
Please report to the mod_perl 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. Serving looks, but make it a roadmap. π
π See Also π
- the mod_perl 1.0 backward compatibility document
- porting Perl modules
- porting XS modules
Apache2::porting
Β©οΈ Copyright Β©οΈ
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
π«Ά Authors π«Ά
The mod_perl development team and numerous contributors.
And that's a wrap, bestie! π This lil manual page came to you from perl v5.42.3, dated 2026-08-20, filed under libapa...dLookup(3pm). Go forth and load your modules, you absolute main character. πΈπ¦
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-perl2 2.0.13-2build3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms