=head1 NAME

Apache::ServerUtil - Perl API for XXX




=head1 Synopsis

  use Apache::ServerUtil ();
  
  $s = Apache->server;
  my $srv_cfg = $s->dir_config;
  
  # get 'conf/' dir path using $s
  my $conf_dir = $s->server_root_relative('conf');
  
  # server level PerlOptions flags lookup
  $s->push_handlers(ChildExit => \&child_exit)
      if $s->is_perl_option_enabled('ChildExit');



META: to be completed




=head1 Description

C<Apache::ServerUtil> provides the Perl API for Apache server object.

META: to be completed



=head1 Constants



=head2 C<Apache::Server::server_root>

returns the value set by the C<ServerRoot> directive.


=head1 Functions API




=head2 C<add_version_component>

META: Autogenerated - needs to be reviewed/completed

Add a component to the version string

  add_version_component($pconf_pool, $component);

=over 4

=item arg1: C<$pconf> (C<L<APR::Pool|docs::2.0::api::APR::Pool>>)

The pool to allocate the component from (should really be a
C<$pconf_pool>)

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

The string to add

=item ret: no return value

=back





=head2 C<exists_config_define>

Check for a definition from the server command line

  $result = Apache::Server::exists_config_define($name);

=over 4

=item arg1: C<$name> (string)

The define to check for

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

true if defined, false otherwise

=back

For example:

  print "this is mp2" if Apache::Server::exists_config_define('MODPERL2');





=head2 C<get_server_built>

META: Autogenerated - needs to be reviewed/completed

Get the date and time that the server was built

  $when_built = Apache::Server::get_server_built();

=over 4

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

The server build time string

=back




=head2 C<get_server_version>

Get the server version string

  Apache::Server::get_server_version();

=over 4

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

The server version string

=back



=head1 Methods API

C<Apache::ServerUtil> provides the following functions and/or methods:



=head2 server_root_relative()

Returns the canonical form of the filename made absolute to
C<ServerRoot>:

  $path = $s->server_root_relative($fname);

=over 4

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

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

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

=back

C<$fname> is appended to the value of C<ServerRoot> and returned. For
example:

  my $log_dir = Apache::Server::server_root_relative($r->pool, 'logs');

If C<$fname> is not specified, the value of C<ServerRoot> is returned
with a trailing C</>. (it's the same as using C<''> as C<$fname>'s
value).

Also see the C<L<Apache::Server::server_root|/C_Apache__Server__server_root_>>
constant.




=head2 C<error_log2stderr>

META: Autogenerated - needs to be reviewed/completed

Convert stderr to the error log

  $s->error_log2stderr();

=over 4

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

The current server

=item ret: no return value

=back



=head2 C<psignature>

META: Autogenerated - needs to be reviewed/completed

Get HTML describing the address and (optionally) admin of the server.

  $sig = $r->psignature($prefix);

=over 4

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

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

Text which is prepended to the return value

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

HTML describing the server

=back





=head2 C<dir_config>

dir_config() provides an interface for the per-server variables
specified by the C<PerlSetVar> and C<PerlAddVar> directives, and also
can be manipulated via the C<APR::Table> methods.

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

=over 4

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

=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.

  $t = $s->dir_config();

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

  @values = $s->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 = $s->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.

  $s->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.

  $s->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.





=head2 C<is_perl_option_enabled>

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

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


=over 4

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

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

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

=back

For example to check whether the C<ChildExit> hook is enabled (which
can be disabled with C<PerlOptions -ChildExit>) and configure some
handlers to run if enabled:

  $s->push_handlers(ChildExit => \&child_exit)
      if $s->is_perl_option_enabled('ChildExit');

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




=head2 C<get_handlers>

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

  @handlers = $s->get_handlers($hook_name);

=over 4

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

=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 references to the handler subroutines

=back

For example:

  @handlers = $s->get_handlers('PerlResponseHandler');




=head2 C<push_handlers>

META: Autogenerated - needs to be reviewed/completed

Add one or more handlers to a list of handlers to be called for a
given phase.

  $s->push_handlers($hook_name => \&handler);
  $s->push_handlers($hook_name => [\&handler, \&handler2]);

=over 4

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

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

a string representing the phase to handle. 

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

a reference to a list of references to the handler subroutines, or a
single reference to a handler subroutine

=item ret: no return value

=back

Examples:

  $s->push_handlers(PerlResponseHandler => \&handler);
  $s->push_handlers(PerlResponseHandler => [\&handler, \&handler2]);

  # XXX: not implemented yet
  $s->push_handlers(PerlResponseHandler => sub {...});



=head2 C<set_handlers>

META: Autogenerated - needs to be reviewed/completed

Set a list of handlers to be called for a given phase.

  $s->set_handlers($hook_name => \&handler);
  $s->set_handlers($hook_name => [\&handler, \&handler2]);

=over 4

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

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

a string representing the phase to handle.

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

a reference to a list of references to the handler subroutines, or a
single reference to a handler subroutine

=item ret: no return value

=back

Examples:

  $s->set_handlers(PerlResponseHandler => \&handler);
  $s->set_handlers(PerlResponseHandler => [\&handler, \&handler2]);

  # XXX: not implemented yet
  $s->set_handlers(PerlResponseHandler => sub {...});






=head2 C<method_register>

META: Autogenerated - needs to be reviewed/completed

Register a new request method, and return the offset that will be
associated with that method.

  $ret = $p->method_register($methname);

=over 4

=item arg1: C<$p> (C<L<APR::Pool|docs::2.0::api::APR::Pool>>)

The pool to create registered method numbers from.

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

The name of the new method to register.

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

Ab int value representing an offset into a bitmask.

=back






=head2 C<get_status_line>

META: Autogenerated - needs to be reviewed/completed

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

=over 4

=item arg1: C<$status> (integer)

The HTTP status code

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

The Status-Line

=back






=head2 C<server>

Get the main server's object

  $main_s = Apache->server();

=over 4

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

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

=back




=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

