You are on page 1of 2

mod perl Quick Reference Card $r->send_http_header( $content_type  ); $aref = $r->get_handlers( $str );

Revision 1.0 for mod perl version 1.19 Server core functions Apache->httpd_conf( $str );
Andrew Ford refcards.com TM $r->chdir_file( $file ); $bool = $r->module( $name );
$r->child_terminate(); $bool = Apache->perl_hook( $name );
mod perl is an Apache module, created by Doug MacEachern, $r->post_connection( $code_ref );
that embeds a Perl interpreter within the server. It provides a Perl $r->hard_timeout( $msg );
$r->internal_redirect( $newplace ); $r->push_handlers( $str => $code_ref );
API to Apache and adds a number of Apache configuration direc-
$r->internal_redirect_handler( $newplace ); $r = Apache->request( $r );
tives. Scripts using mod perl should import the Apache module, $r->set_handlers( $str => $aref );
Apache::Constants, and other Apache:: modules. A reference to $bool = $r->is_initial_req();
the request object (denoted below by $r) is passed to Perl handlers $bool = $r->is_main(); Apache::SubRequest class
when they are invoked. $r->kill_timeout(); $subr = $r->lookup_uri($uri);
$str = $r->location(); $subr = $r->lookup_file($filename);
Client request methods $req = $r->last(); $rc = $subr->run();
$r = Apache->request(); $req = $r->main();
$str = $r->args(); # or %hash = ... Apache::Server class
$req = $r->next();
$c = $r->connection # see Apache::Connection $str = $r->notes( $k ,$v ); # or $tab = $r->notes() $s = Apache->server # or $r->server
$str = $r->content(); # or %hash = ... $bool = $s->is_virtual();
$str = $r->filename( $newval  );
$req = $r->prev();
$r->register_cleanup( $code_ref ); $s->log_error();
$r->finfo(); $r->reset_timeout(); $aref = $s->names();
$str = $r->get_remote_host( $lookup_type  ); $r->soft_timeout( $msg ); $s = $s->next();
$str = $r->subprocess_env( $k , $v  );
# use Apache::Constants :remotehost tag $num = $s->port();
$str = $r->get_remote_logname(); $str = $s->server_admin();
$str = $r->header_in( $hdr , $newval  ); Server configuration methods $str = $s->server_hostname();
$bool = $r->header_only(); $str = $r->dir_config($k); #or $tab = $r->dir_config() $num = $s->timeout( $newval  );
$href = $r->headers_in(); # or %hash = ... $str = $r->document_root(); $s->warn();
$str = $r->method( $newval  ); $str = $r->get_server_name(); Apache::Connection class
$num = $r->method_number( $nv ); # use :methods tag $num = $r->get_server_port();
$u = $r->parsed_uri(); # see Apache::URI $str = $r->server_root_relative( $obj  ); $bool = $c->aborted();
$str = $c->auth_type();
$str = $r->path_info( $newval  ); Logging and the Apache::Log class $addr = $c->local_addr();
$str = $r->protocol(); $str = $r->as_string(); $addr = $c->remote_addr( $addr  );
$bool = $r->proxyreq( $newval  ); $r->log_reason( $message, $file ); $str = $c->remote_host();
$r->read( $buf, $bytes_to_read ); $r->log_error( $message ); $str = $c->remote_ip( $ip );
$s = $r->server # see Apache::Server $r->warn( $message ); $str = $c->remote_logname();
$str = $c->user( $username  );
$str = $r->the_request(); $log = $r->log();
$str = $r->uri( $newval  ); $log = $s->log();
$log->emerg (  $str ...  $code_ref  ); Apache::Table class
$tab = Apache::Table->new( $r , $size );
Server response methods
$num = $r->bytes_sent(); $log->alert (  $msg ...  $code_ref  );
$r->cgi_header_out( $hdr , $newval  ); $log->crit (  $msg ...  $code_ref  ); $tab->add( $key, $str_or_aref );
$str = $r->content_encoding( $newval  ); $log->error (  $msg ...  $code_ref  ); $tab->clear();
$log->warn (  $msg ...  $code_ref  );
$tab->do( $code_ref );
$aref = $r->content_languages( $newval  ); $tab->merge( $key, $str_or_aref );
$str = $r->content_type( $newval  ); $log->notice(  $msg ...  $code_ref  ); $tab->set( $key, $str );
$r->custom_response( $code, $uri ); $log->info (  $msg ...  $code_ref  ); $str = $tab->get( $key ); # or @list = ...
$str = $r->err_header_out( $hdr , $newval  ); $log->debug (  $msg ...  $code_ref  ); $tab->unset($key);
$href = $r->err_headers_out(); # or %hash = ... Access control methods Apache::URI class
$str = $r->handler( $newval  ); $opts = $r->allow_options(); # use :options tag $uri = Apache::URI->parse( $r , $string_uri  );
$str = $r->header_out( $hdr , $newval  ); $str = $r->auth_name( $newval  ); $str = $uri->unparse();
$href = $r->headers_out(); # or %hash = ... $str = $r->auth_type(); $str = $uri->component( $newval  );
$bool = $r->no_cache( $newval  ); ($rc, $pw) = $r->get_basic_auth_pw(); (where component is one of: fragment, hostinfo, hostname,
$num = $r->request_time(); $r->note_basic_auth_failure(); password, path_info, path, port, query, rpath, scheme, user)
$num = $r->status( $newval  ); $aref = $r->requires(); Apache::Util class
$str = $r->status_line( $newval  ); $flag = $r->satisfies(); # use :satisfies tag $str = Apache::Util::escape_html( $html );
Sending data to the client $bool = $r->some_auth_required(); $str = Apache::Util::escape_uri( $uri );
$r->print( @list ); # checks $| mod_perl specific methods $str = Apache::Util::ht_time($time , $fmt , $bool   );
$r->printf( $format, @args ); $str = $r->current_callback(); $secs = Apache::Util::parsedate( $date_str );
$r->rflush(); $bool = $r->define( $name ); $num = Apache::Util::size_string( $num );
$r->send_cgi_header( $str ); Apache->exit( $code  ); $str = Apache::Util::unescape_uri( $uri );
$len = $r->send_fd( $filehandle ); $fh = Apache->gensym(); $str = Apache::Util::unescape_uri_info( $uri );
1 2 3
Apache::Constants class HTTP 1.1 headers Apache mod perl configuration directives
The following export tag groups are defined (HTTP status code mod perl enables Apache to be configured using Perl statements
synonyms are given in brackets): that are contained within <Perl>. . . </Perl> sections and adds the
Apache configuration directives listed below. Each directive is
:common : OK, DECLINED , DONE, NOT_FOUND , FORBIDDEN , Syntax Category given with its arguments; defaults are given where appropriate in
AUTH_REQUIRED (HTTP_UNAUTHORIZED ), SERVER_ERROR Accept: media-types  ;q=qvalue  , ...  REQUEST parentheses at the end of the line, followed by the symbol ❖ to
Accept-Charset: charset  ;q=qvalue  , ...  REQUEST mark directives only valid in a directory section or .htaccess file.
Accept-Encoding: encoding  ;q=qvalue  , ...
:response : DOCUMENT_FOLLOWS (HTTP_OK ),
REQUEST
Accept-Language: lang  ;q=qvalue  , ...
MOVED (HTTP_MOVED_PERMANENTLY),
REQUEST
Accept-Ranges: bytes
none
REDIRECT (HTTP_MOVED_TEMPORARILY), PerlAccessHandler handler
RESPONSE
USE_LOCAL_COPY (HTTP_NOT_MODIFIED ), PerlAuthenHandler handler
Age: seconds RESPONSE
Allow: method  , ...
BAD_REQUEST , BAD_GATEWAY , NOT_IMPLEMENTED , PerlAuthzHandler handler
ENTITY
CONTINUE , NOT_AUTHORITATIVE PerlChildExitHandler handler ❖
Authorization: scheme credentials REQUEST
PerlChildInitHandler handler ❖
:methods : M_CONNECT , M_COPY, M_DELETE , M_GET, M_INVALID , Cache-Control: directive GENERAL
PerlCleanupHandler handler
M_LOCK, M_MKCOL , M_MOVE, M_OPTIONS , M_PATCH , M_POST, Connection: close GENERAL
Content-Base: uri
PerlDispatchHandler handler
M_PROPFIND , M_PROPPATCH , M_PUT, M_TRACE , M_UNLOCK , METHODS ENTITY
PerlFixupHandler handler
PerlFreshRestart  On  Off 
Content-Encoding: enc ENTITY
:options : OPT_ALL OPT_NONE , OPT_INDEXES , OPT_INCLUDES , Content-Language: lang ENTITY
(On) ❖
OPT_SYM_LINKS , OPT_EXECCGI , OPT_UNSET , Content-Length: len ENTITY
PerlHandler handler
OPT_INCNOEXEC , OPT_SYM_OWNER , OPT_MULTI , Content-MD5: digest ENTITY
PerlHeaderParserHandler handler
Content-Range: bytes range/length ENTITY
PerlInitHandler handler
:satisfies : SATISFY_ALL , SATISFY_ANY , SATISFY_NOSPEC PerlLogHandler handler
Content-Type: media-type ENTITY
:server : MODULE_MAGIC_NUMBER , SERVER_BUILT , SERVER_VERSION Cookie: name=value  ; ...  REQUEST
PerlModule
Date: date GENERAL PerlPassEnv name ... ❖
:remotehost : REMOTE_HOST , REMOTE_NAME , REMOTE_NOLOOKUP , ETag: entity-tag RESPONSE PerlPostReadRequestHandler handler ❖
REMOTE_DOUBLE_REV Expect: expectation PerlRequire script-file
PerlSendHeader  On  Off 
REQUEST
Expires: date ENTITY (Off)
:http includes only those HTTP status code constants shown below in PerlSetEnv name value
From: email-address REQUEST
Host: hostname  :port 
bold type (other HTTP constants may be imported explicitly): PerlSetVar name value
PerlSetupEnv  On  Off 
REQUEST
100 HTTP_CONTINUE 405 HTTP_METHOD_NOT_ALLOWED (Off)
If-Match: entity-tag REQUEST
101 HTTP_SWITCHING_PROTOCOLS 406 HTTP_NOT_ACCEPTABLE
If-Modified-Since: date REQUEST PerlTaintCheck  On  Off  (Off) ❖
200 HTTP_OK 407 HTTP_PROXY_AUTHENTICATION_
If-None-Match: entity-tag REQUEST PerlTransHandler handler ❖
If-Range: entity tag
date
201 HTTP_CREATED REQUIRED
REQUEST PerlTypeHandler handler
PerlWarn  On  Off 
202 HTTP_ACCEPTED 408 HTTP_REQUEST_TIMEOUT
203 HTTP_NON_AUTHORITATIVE 409 HTTP_CONFLICT
If-Unmodified-Since: date REQUEST (Off) ❖
Last-Modified: date ENTITY
204 HTTP_NO_CONTENT 410 HTTP_GONE
Location: uri RESPONSE Resources
205 HTTP_RESET_CONTENT 411 HTTP_LENGTH REQUIRED
MIME-Version: version GENERAL
http://perl.apache.org The Apache/Perl Integration Project
206 HTTP_PARTIAL_CONTENT 412 HTTP_PRECONDITION_FAILED
Max-Forwards: number REQUEST
Pragma: no-cache
extension-pragma
300 HTTP_MULTIPLE_CHOICES 413 HTTP_REQUEST_ENTITY_TOO_LARGE http://www.modperl.com Writing Apache Modules home page
GENERAL
301 HTTP_MOVED_PERMANENTLY 414 HTTP_REQUEST_URI_TOO_LARGE http://www.apache.org Apache home page
Proxy-Authenticate: challenge RESPONSE
302 HTTP_MOVED_TEMPORARILY 415 HTTP_UNSUPPORTED_MEDIA_TYPE http://www.perl.com Perl home page
Proxy-Authorization: credentials REQUEST
303 HTTP_SEE_OTHER 500 HTTP_INTERNAL_SERVER_ERROR http://www.refcards.com Quick reference cards
Public: method ... RESPONSE
Range: bytes=n  -m  , ...
304 HTTP_NOT_MODIFIED 501 HTTP_NOT IMPLEMENTED
REQUEST
305 HTTP_USE_PROXY 502 HTTP_BAD_GATEWAY
Referer: url REQUEST
Retry-After: date
seconds
400 HTTP_BAD_REQUEST 503 HTTP_SERVICE_UNAVAILABLE mod perl Quick Reference Card
RESPONSE
401 HTTP_UNAUTHORIZED 504 HTTP_GATEWAY_TIME_OUT A refcards.com TM quick reference card
Server: string RESPONSE
Set-Cookie: name=value  ; options  c 1998, 1.0
402 HTTP_PAYMENT_REQUIRED 505 HTTP_VERSION_NOT_SUPPORTED Revision for mod perl version 1.19 [May 1999]
RESPONSE
403 HTTP_FORBIDDEN 506 HTTP_VARIANT_ALSO_VARIES 1999 Ford & Mason Ltd. All rights reserved.
TE: coding REQUEST
404 HTTP_NOT_FOUND Trailer: header GENERAL Permission is granted to print and duplicate this card for personal or in-
Transfer-Encoding: coding GENERAL dividual, internal business use. Copies of this card (& others) can be or-
Upgrade: protocol  , ...
Magic global variables GENERAL dered through our web site: http://www.refcards.com, which also has
$0, $^X, $|, $/, %@, %SIG, @INC, %INC, %ENV{MOD_PERL} , User-Agent: string REQUEST versions available for downloading.
%ENV{GATEWAY_INTERFACE}, %ENV{PERL_SEND_HEADER} Vary: header  , ...  RESPONSE Please send feedback to: feedback@refcards.com
Special package globals Via:  protocol/ version  (comment)  , ... GENERAL refcards.com is a trademark of Ford & Mason Ltd.
$Apache::Server::CWD $Apache::Server::SaveConfig WWW-Authenticate: scheme realm RESPONSE Use of the Camel for Perl is a trademark of O’Reilly & Associates – used by permis-
$Apache::Server::ReStarting $Apache::Server::Starting Warning: code agent "text"  date  GENERAL sion.

4 5 6

You might also like