The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache::ServerUtil - Perl API for XXX

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

Description

Apache::ServerUtil provides the Perl API for Apache server object.

META: to be completed

Constants

Apache::server_root

returns the value set by the ServerRoot directive.

Functions API

add_config

META: Autogenerated - needs to be reviewed/completed

  $ret = $s->add_config($lines, $path, $override);
obj: $r (Apache::Server)
arg1: $lines (ARRAY ref)
opt arg3: $path (scalar)
opt arg4: $override (string)
ret: $ret (string)

See also: $r->add_config

add_version_component

META: Autogenerated - needs to be reviewed/completed

Add a component to the version string

  add_version_component($pconf_pool, $component);
obj: $pconf (APR::Pool)

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

arg1: $component (string)

The string to add

ret: no return value

exists_config_define

Check for a definition from the server command line

  $result = Apache::exists_config_define($name);
obj: $name (string)

The define to check for

ret: $result (integer)

true if defined, false otherwise

For example:

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

get_server_built

META: Autogenerated - needs to be reviewed/completed

Get the date and time that the server was built

  $when_built = Apache::get_server_built();
ret: $when_built (string)

The server build time string

get_server_version

Get the server version string

  Apache::get_server_version();
ret: $ret (string)

The server version string

Methods API

Apache::ServerUtil provides the following functions and/or methods:

server_root_relative()

Returns the canonical form of the filename made absolute to ServerRoot:

  $path = $s->server_root_relative($fname);
obj: $s (Apache::Server)
opt arg2: $fname (string)
ret: $path (string)

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

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

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

Also see the Apache::server_root constant.

error_log2stderr

META: Autogenerated - needs to be reviewed/completed

Convert stderr to the error log

  $s->error_log2stderr();
obj: $s (Apache::Server)

The current server

ret: no return value

psignature

META: Autogenerated - needs to be reviewed/completed

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

  $sig = $r->psignature($prefix);
obj: $r (Apache::RequestRec)
arg1: $prefix (string)

Text which is prepended to the return value

ret: $sig (string)

HTML describing the server

dir_config

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

  $table  = $s->dir_config();
  $value  = $s->dir_config($key);
  @values = $s->dir_config($key);
  $s->dir_config($key, $val);
obj: $s (Apache::Server)
opt arg2: $key (string)
opt arg3: $val (string)
ret: $ret (scalar)

Depends on the passed arguments, see further discussion

The keys are case-insensitive.

  $t = $s->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 APR::Table.

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

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

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

is_perl_option_enabled

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

  $result = $s->is_perl_option_enabled($flag);
obj: $s (Apache::Server)
arg1: $flag (string)
ret: $result (integer)

For example to check whether the ChildExit hook is enabled (which can be disabled with 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: PerlOptions and the equivalent function for directory level PerlOptions flags.

get_handlers

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

  @handlers = $s->get_handlers($hook_name);
obj: $s (Apache::Server)
arg1: $hook_name (string)

a string representing the phase to handle.

ret: @handlers (CODE ref or ref to ARRAY of CODE refs)

a list of references to the handler subroutines

For example:

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

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]);
obj: $s (Apache::Server)
arg1: $hook_name (string)

a string representing the phase to handle.

arg2: $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

ret: no return value

Examples:

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

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

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]);
obj: $s (Apache::Server)
arg1: $hook_name (string)

a string representing the phase to handle.

arg2: $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

ret: no return value

Examples:

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

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

server

Get the main server's object

  $main_s = Apache->server();
obj: Apache (class name)
ret: $main_s (Apache::Server)

See Also

mod_perl 2.0 documentation.

Copyright

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

Authors

The mod_perl development team and numerous contributors.