Apache::RequestUtil - Perl API for Apache request record utils
use Apache::RequestUtil (); # directory level PerlOptions flags lookup $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
META: to be completed
request
Retrieve the (Apache::RequestRec) object for the current request.
Apache::RequestRec
$r = Apache->request;
Apache
The Apache class
$r
This method is only available if PerlOptions +GlobalRequest is in effect.
PerlOptions +GlobalRequest
default_type
META: Autogenerated - needs to be reviewed/completed
Retrieve the value of the DefaultType directive, or text/plain if not set
$ret = $r->default_type();
The current request
$ret
The default type
document_root
Retrieve the document root for this server
$ret = $r->document_root();
The document root
get_limit_req_body
Return the limit on bytes in request msg body
$ret = $r->get_limit_req_body();
the maximum number of bytes in the request msg body
get_server_name
Get the current server name from the request
$ret = $r->get_server_name();
the server name
get_server_port
Get the current server port
$ret = $r->get_server_port();
The server's port
get_status_line
Return the Status-Line for a given status code (excluding the HTTP-Version field). If an invalid or unknown status code is passed, "500 Internal Server Error" will be returned.
$ret = get_status_line($status);
$status
The HTTP status code
The Status-Line
is_initial_req
Determine if the current request is the main request or a sub requests
$ret = $r->is_initial_req();
method_register
Register a new request method, and return the offset that will be associated with that method.
$ret = $p->method_register($methname);
$p
APR::Pool
The pool to create registered method numbers from.
$methname
The name of the new method to register.
Ab int value representing an offset into a bitmask.
add_config
$ret = $r->add_config($lines, $path, $override);
$lines
$path
$override
See also: $s->add_config
$s->add_config
location
$location = $r->location($location);
$location
location_merge
$ret = $r->location_merge($location);
pnotes
Notes from one module to another
$pnotes = $r->pnotes(); $pnotes = $r->pnotes($new_pnotes);
$new_pnotes
APR::Table
$pnotes
Similar to (Apache::RequestRec), but values can be any perl variables. That also means that it can be used only between perl modules.
no_cache
$ret = $r->no_cache($flag);
$flag
as_string
$string = $r->as_string();
$string
get_handlers
Returns a reference to a list of handlers enabled for a given phase.
$handlers_list = $r->get_handlers($hook_name);
$hook_name
a string representing the phase to handle.
@handlers
a list of handler subroutines CODE references
For example:
A list of handlers configured to run at the response phase:
my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };
push_handlers
Add one or more handlers to a list of handlers to be called for a given phase.
$r->push_handlers($hook_name => \&handler); $r->push_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
$handlers
a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).
if more than one passed, use a reference to an array of CODE refs and/or subroutine names.
Examples:
A single handler:
$r->push_handlers(PerlResponseHandler => \&handler);
Multiple handlers:
$r->push_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);
Anonymous functions:
$r->push_handlers(PerlLogHandler => sub { return Apache::OK });
set_handlers
Set a list of handlers to be called for a given phase. Any previously set handlers are forgotten.
$r->set_handlers($hook_name => \&handler); $r->set_handlers($hook_name => ['Foo::Bar::handler', \&handler2]); $r->set_handlers($hook_name => []); $r->set_handlers($hook_name => undef);
a reference to a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).
if the argument is undef or [] the list of handlers is reset to zero.
undef
$r->set_handlers(PerlResponseHandler => \&handler);
$r->set_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);
$r->set_handlers(PerlLogHandler => sub { return Apache::OK });
Reset any previously set handlers:
$r->set_handlers(PerlCleanupHandler => []);
or
$r->set_handlers(PerlCleanupHandler => undef);
set_basic_credentials
$r->set_basic_credentials($username, $password);
$username
$password
slurp_filename
Return a reference to contents of $r->filename.
$r->filename
$content = $r->slurp_filename($tainted);
$tainted
By default the returned data is tainted (if run under -T). If an optional $tainted flag is set to zero, the data will be marked as non-tainted. Do not set this flag to zero unless you know what you are doing, you may create a security hole in your program if you do. For more information see the perlsec manpage. If you wonder why this option is available, it is used internally by the ModPerl::Registry handler and friends, because the CGI scripts that it reads are considered safe (you could just as well require() them).
-T
ModPerl::Registry
require()
$content
is_perl_option_enabled
check whether a directory level PerlOptions flag is enabled or not.
$result = $r->is_perl_option_enabled($flag);
$result
For example to check whether the SetupEnv option is enabled for the current request (which can be disabled with PerlOptions -SetupEnv) and populate the environment variables table if disabled:
SetupEnv
PerlOptions -SetupEnv
$r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
See also: PerlOptions and the equivalent function for server level PerlOptions flags.
dir_config
dir_config() provides an interface for the per-directory variable specified by the PerlSetVar and PerlAddVar directives, and also can be manipulated via the APR::Table methods.
PerlSetVar
PerlAddVar
$table = $r->dir_config(); $value = $r->dir_config($key); @values = $r->dir_config($key); $r->dir_config($key, $val);
$key
$val
Depends on the passed arguments, see further discussion
The keys are case-insensitive.
$apr_table = $r->dir_config();
dir_config() called in a scalar context without the $key argument returns a HASH reference blessed into the APR::Table class. This object can be manipulated via the APR::Table methods. For available methods see the APR::Table manpage.
@values = $r->dir_config($key);
If the $key argument is passed in the list context a list of all matching values will be returned. This method is ineffective for big tables, as it does a linear search of the table. Thefore avoid using this way of calling dir_config() unless you know that there could be more than one value for the wanted key and all the values are wanted.
$value = $r->dir_config($key);
If the $key argument is passed in the scalar context only a single value will be returned. Since the table preserves the insertion order, if there is more than one value for the same key, the oldest value assosiated with the desired key is returned. Calling in the scalar context is also much faster, as it'll stop searching the table as soon as the first match happens.
$r->dir_config($key => $val);
If the $key and the $val arguments are used, the set() operation will happen: all existing values associated with the key $key (and the key itself) will be deleted and $value will be placed instead.
$value
$r->dir_config($key => undef);
If $val is undef the unset() operation will happen: all existing values associated with the key $key (and the key itself) will be deleted.
mod_perl 2.0 documentation.
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 1.1.
The mod_perl development team and numerous contributors.
To install mod_perl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm mod_perl
CPAN shell
perl -MCPAN -e shell install mod_perl
For more information on module installation, please visit the detailed CPAN module installation guide.