mod_perl logo
perl icon







previous page: Apache::Server - Perl API for for Apache server record accessorspage up: mod_perl APIsnext page: Apache::SubProcess -- Executing SubProcesses from mod_perl


Apache::ServerUtil - Perl API for XXX











Writing Apache Modules with Perl and C

Writing Apache Modules with Perl and C

By Lincoln Stein, Doug MacEachern
Embedding Perl in HTML with Mason

Embedding Perl in HTML with Mason

By Dave Rolsky, Ken Williams
Practical mod_perl

Practical mod_perl

By Stas Bekman, Eric Cholet


Table of Contents

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



TOP

Description

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

META: to be completed



TOP

Constants



TOP

Apache::Server::server_root

returns the value set by the ServerRoot directive.



TOP

Functions API



TOP

add_version_component

META: Autogenerated - needs to be reviewed/completed

Add a component to the version string

  add_version_component($pconf_pool, $component);


TOP

exists_config_define

Check for a definition from the server command line

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

For example:

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


TOP

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


TOP

get_server_version

Get the server version string

  Apache::Server::get_server_version();


TOP

Methods API

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



TOP

server_root_relative()

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

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

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

  my $log_dir = Apache::Server::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::server_root constant.



TOP

error_log2stderr

META: Autogenerated - needs to be reviewed/completed

Convert stderr to the error log

  $s->error_log2stderr();


TOP

psignature

META: Autogenerated - needs to be reviewed/completed

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

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


TOP

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

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.



TOP

is_perl_option_enabled

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

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

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.



TOP

get_handlers

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

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

For example:

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


TOP

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

Examples:

  $s->push_handlers(PerlResponseHandler => \&handler);
  $s->push_handlers(PerlResponseHandler => [\&handler, \&handler2]);
  # XXX: not implemented yet
  $s->push_handlers(PerlResponseHandler => sub {...});


TOP

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

Examples:

  $s->set_handlers(PerlResponseHandler => \&handler);
  $s->set_handlers(PerlResponseHandler => [\&handler, \&handler2]);
  # XXX: not implemented yet
  $s->set_handlers(PerlResponseHandler => sub {...});


TOP

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


TOP

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


TOP

server

Get the main server's object

  $main_s = Apache->server();


TOP

See Also

mod_perl 2.0 documentation.



TOP

Copyright

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



TOP

Authors

The mod_perl development team and numerous contributors.







TOP
previous page: Apache::Server - Perl API for for Apache server record accessorspage up: mod_perl APIsnext page: Apache::SubProcess -- Executing SubProcesses from mod_perl