|
|
addap_api_major_versionap_api_minor_versioncmdsget_configfind_linked_moduleloadedmodule_indexnamenextremove_loaded_moduletop_module
Apache2::Module - Perl API for creating and working with Apache modules
use Apache2::Module ();
#Define a configuration directive
my @directives = (
{
name => 'MyDirective',
}
);
Apache2::Module::add(__PACKAGE__, \@directives);
# iterate over the whole module list
for (my $modp = Apache2::Module::top_module(); $modp; $modp = $modp->next) {
my $name = $modp->name;
my $index = $modp->module_index;
my $ap_api_major_version = $modp->ap_api_major_version;
my $ap_api_minor_version = $modp->ap_api_minor_version;
my $commands = $modp->cmds;
}
# find a specific module
my $module = Apache2::Module::find_linked_module('mod_ssl.c');
# remove a specific module
$module->remove_loaded_module();
# access module configuration from a directive
sub MyDirective {
my ($self, $parms, $args) = @_;
my $srv_cfg = Apache2::Module::get_config($self, $parms->server);
[...]
}
# test if an Apache module is loaded
if (Apache2::Module::loaded('mod_ssl.c')) {
[...]
}
# test if a Perl module is loaded
if (Apache2::Module::loaded('Apache2::Status')) {
[...]
}
Apache2::Module provides the Perl API for creating and working with
Apache modules
See Apache Server Configuration Customization in Perl.
Apache2::Module provides the following functions and/or methods:
addAdd a module's custom configuration directive to Apache.
Apache2::Module::add($package, $cmds);
$package ( string )
the package of the module to add
$cmds ( ARRAY of HASH refs )
the list of configuration directives to add
See also Apache Server Configuration Customization in Perl.
ap_api_major_versionGet the httpd API version this module was build against, not the module's version.
$major_version = $module->ap_api_major_version();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$major_version ( integer )
This methid is used to check that module is compatible with this version of the server before loading it.
ap_api_minor_versionGet the module API minor version.
$minor_version = $module->ap_api_minor_version();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$minor_version ( integer )
ap_api_minor_version() provides API feature milestones.
It's not checked during module init.
cmdsGet the Apache2::Command|docs::2.0::api::Apache2::Command object,
describing all of the directives this module defines.
$command = $module->cmds();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$command
( Apache2::Command object|docs::2.0::api::Apache2::Command )
get_configRetrieve a module's configuration. Used by configuration directives.
$cfg = Apache2::Module::get_config($class, $server, $dir_config); $cfg = Apache2::Module::get_config($class, $server); $cfg = $self->get_config($server, $dir_config); $cfg = $self->get_config($server);
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$class ( string )
The Perl package this configuration is for
$server
( Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec )
The current server, typically
$r->server|docs::2.0::api::Apache2::ServerUtil or
$parms->server|docs::2.0::api::Apache2::CmdParms.
$dir_config
( Apache2::ConfVector object|docs::2.0::api::Apache2::ConfVector )
By default, the configuration returned is the server level one. To
retrieve the per directory configuration, use
$r->per_dir_config|docs::2.0::api::Apache2::RequestRec as a
last argument.
$cfg (HASH reference)
A reference to the hash holding the module configuration data.
See also Apache Server Configuration Customization in Perl.
find_linked_moduleFind a module based on the name of the module
$module = Apache2::Module::find_linked_module($name);
$name ( string )
The name of the module ending in .c
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
The module object if found, undef otherwise.
For example:
my $module = Apache2::Module::find_linked_module('mod_ssl.c');
loadedDetermine if a certain module is loaded
$loaded = Apache2::Module::loaded($module);
$module ( string )
The name of the module to search for.
If $module ends with .c, search all the modules, statically
compiled and dynamically loaded.
If $module ends with .so, search only the dynamically loaded
modules.
If $module doesn't contain a ., search the loaded Perl modules
(checks %INC).
$loaded ( boolean )
Returns true if the module is loaded, false otherwise.
For example, to test if this server supports ssl:
if (Apache2::Module::loaded('mod_ssl.c')) {
[...]
}
To test is this server dynamically loaded mod_perl:
if (Apache2::Module::loaded('mod_perl.so')) {
[...]
}
To test if Apache2::Status|docs::2.0::api::Apache2::Status is
loaded:
if (Apache2::Module::loaded('Apache2::Status')) {
[...]
}
module_indexGet the index to this modules structures in config vectors.
$index = $module->module_index();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$index ( integer )
nameGet the name of the module's .c file
$name = $module->name();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$name ( string )
For example a mod_perl module, will return: mod_perl.c.
nextGet the next module in the list, undef if this is the last module
in the list.
$next_module = $module->next();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
$next_module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
remove_loaded_moduleRemove a module from the list of loaded modules permanently.
$module->remove_loaded_module();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
top_moduleReturns the first module in the module list. Usefull to start a module iteration.
$module = Apache2::Module::top_module();
$module
( Apache2::Module object|docs::2.0::api::Apache2::Module )
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.