=head1 NAME

Apache::RequestUtil - Perl API for Apache request record utils




=head1 Synopsis

  use Apache::RequestUtil ();
  
  # directory level PerlOptions flags lookup
  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');

META: to be completed




=head1 Description

META: to be completed



=head1 Class methods API

=head2 C<request>

Retrieve the
(C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>) object
for the current request.

  $r = Apache->request;

=over 4

=item arg1: C<Apache> (class name)

The Apache class

=item ret: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item since: 1.99_10

=back

This method is only available if C<L<PerlOptions
+GlobalRequest|docs::2.0::user::config::config/C_GlobalRequest_>> is
in effect.


=head1 Methods API



=head2 C<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();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

The current request

=item ret: C<$ret> (string)

The default type

=back





=head2 C<document_root>

META: Autogenerated - needs to be reviewed/completed

Retrieve the document root for this server

  $ret = $r->document_root();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

The current request

=item ret: C<$ret> (string)

The document root

=back





=head2 C<get_limit_req_body>

META: Autogenerated - needs to be reviewed/completed

Return the limit on bytes in request msg body

  $ret = $r->get_limit_req_body();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

The current request

=item ret: C<$ret> (integer)

the maximum number of bytes in the request msg body

=back





=head2 C<get_server_name>

META: Autogenerated - needs to be reviewed/completed

Get the current server name from the request

  $ret = $r->get_server_name();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

The current request

=item ret: C<$ret> (string)

the server name

=back





=head2 C<get_server_port>

META: Autogenerated - needs to be reviewed/completed

Get the current server port

  $ret = $r->get_server_port();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)



=item ret: C<$ret> (integer)

The server's port

=back





=head2 C<is_initial_req>

META: Autogenerated - needs to be reviewed/completed

Determine if the current request is the main request or a sub requests

  $ret = $r->is_initial_req();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

The current request

=item ret: C<$ret> (integer)



=back





=head2 C<add_config>

META: Autogenerated - needs to be reviewed/completed



  $ret = $r->add_config($lines, $path, $override);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$lines> (ARRAY ref)

=item opt arg3: C<$path> (scalar)

=item opt arg4: C<$override> (string)

=item ret: C<$ret> (string)

=back



=head2 C<location>

META: Autogenerated - needs to be reviewed/completed



  $location = $r->location($location);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item opt arg2: C<$location> (string)

=item ret: C<$location> (integer)

=back




=head2 C<location_merge>

META: Autogenerated - needs to be reviewed/completed



  $ret = $r->location_merge($location);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$location> (string)

=item ret: C<$ret> (integer)

=back



=head2 C<pnotes>

META: Autogenerated - needs to be reviewed/completed

Notes from one module to another

  $pnotes = $r->pnotes();
  $pnotes = $r->pnotes($new_pnotes);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item opt arg2: C<$new_pnotes> (C<L<APR::Table|docs::2.0::api::APR::Table>>)

=item ret: C<$pnotes> (C<L<APR::Table|docs::2.0::api::APR::Table>>)


=back

Similar to
(C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec/C_notes_>>),
but values can be any perl variables. That also means that it can be
used only between perl modules.





=head2 C<no_cache>

META: Autogenerated - needs to be reviewed/completed


  $ret = $r->no_cache($flag);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$flag> (number)

=item ret: C<$ret> (integer)

=back




=head2 C<as_string>

META: Autogenerated - needs to be reviewed/completed

  $string = $r->as_string();

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item ret: C<$string> (string)

=back




=head2 C<get_handlers>

Returns a reference to a list of handlers enabled for
a given phase.

  $handlers_list = $r->get_handlers($hook_name);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$hook_name> (string)

a string representing the phase to handle.

=item ret: C<@handlers> (CODE ref or ref to ARRAY of CODE refs)

a list of handler subroutines CODE references

=back

For example:

A list of handlers configured to run at the response phase:

  my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };




=head2 C<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]);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$hook_name> (string)

a string representing the phase to handle.

=item arg3: C<$handlers> (CODE ref or SUB name or ref to an ARRAY of CODE refs)

a reference to 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.

=item ret: no return value

=back

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 });




=head2 C<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);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$hook_name> (string)

a string representing the phase to handle.

=item arg3: C<$handlers> (CODE ref or SUB name or ref to an ARRAY of CODE refs)

a reference to 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.

if the argument is C<undef> or [] the list of handlers is reset to
zero.

=item ret: no return value

=back

Examples:

A single handler:

  $r->set_handlers(PerlResponseHandler => \&handler);

Multiple handlers:

  $r->set_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);

Anonymous functions:

  $r->set_handlers(PerlLogHandler => sub { return Apache::OK });

Reset any previously set handlers:

  $r->set_handlers(PerlCleanupHandler => []);

or

  $r->set_handlers(PerlCleanupHandler => undef);




=head2 C<set_basic_credentials>

META: Autogenerated - needs to be reviewed/completed



  $r->set_basic_credentials($username, $password);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$username> (string)

=item arg3: C<$password> (string)

=item ret: no return value

=back





=head2 C<slurp_filename>

META: Autogenerated - needs to be reviewed/completed


Return a reference to contents of C<$r-E<gt>filename>.

  $content = $r->slurp_filename($tainted);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$tainted> (number)

By default the returned data is tainted (if run under C<-T>). If an
optional C<$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 I<perlsec> manpage. If you wonder why this
option is available, it is used internally by the
C<L<ModPerl::Registry|docs::2.0::api::ModPerl::Registry>> handler and
friends, because the CGI scripts that it reads are considered safe
(you could just as well C<require()> them).

=item ret: C<$content> (scalar)

=back


=head2 C<is_perl_option_enabled>

check whether a directory level PerlOptions flag is enabled or not.

  $result = $r->is_perl_option_enabled($flag);


=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item arg2: C<$flag> (string)

=item ret: C<$result> (integer)

=back

For example to check whether the C<SetupEnv> option is enabled for the
current request (which can be disabled with C<PerlOptions -SetupEnv>)
and populate the environment variables table if disabled:

  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');

See also:
L<PerlOptions|docs::2.0::user::config::config/C_PerlOptions_> and
L<the equivalent function for server level PerlOptions
flags|docs::2.0::api::Apache::ServerUtil/C_is_perl_option_enabled_>.





=head2 C<dir_config>

dir_config() provides an interface for the per-directory variable
specified by the C<PerlSetVar> and C<PerlAddVar> directives, and also
can be manipulated via the C<L<APR::Table|docs::2.0::api::APR::Table>>
methods.

  $table  = $r->dir_config();
  $value  = $r->dir_config($key);
  @values = $r->dir_config($key);
  $r->dir_config($key, $val);

=over 4

=item arg1: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)

=item opt arg2: C<$key> (string)

=item opt arg3: C<$val> (string)

=item ret: C<$ret> (scalar)

Depends on the passed arguments, see further discussion

=back


The keys are case-insensitive.

  $apr_table = $r->dir_config();

dir_config() called in a scalar context without the C<$key> argument
returns a I<HASH> reference blessed into the
C<L<APR::Table|docs::2.0::api::APR::Table>> class. This object can be
manipulated via the C<L<APR::Table|docs::2.0::api::APR::Table>>
methods. For available methods see
the C<L<APR::Table|docs::2.0::api::APR::Table>> manpage.

  @values = $r->dir_config($key);

If the C<$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 C<$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 C<$key> and the C<$val> arguments are used, the set() operation
will happen: all existing values associated with the key C<$key> (and
the key itself) will be deleted and C<$value> will be placed instead.

  $r->dir_config($key => undef);

If C<$val> is I<undef> the unset() operation will happen: all existing
values associated with the key C<$key> (and the key itself) will be
deleted.





=head1 See Also

L<mod_perl 2.0 documentation|docs::2.0::index>.




=head1 Copyright

mod_perl 2.0 and its core modules are copyrighted under
The Apache Software License, Version 1.1.




=head1 Authors

L<The mod_perl development team and numerous
contributors|about::contributors::people>.

=cut

