=head1 NAME
Porting Apache:: Perl Modules from mod_perl 1.0 to 2.0
=head1 Description
This document describes the various options for porting a mod_perl 1.0
Apache module so that it runs on a Apache 2.0 / mod_perl 2.0
server. It's also helpful to those who start developing mod_perl 2.0
handlers.
Developers who need to port modules using XS code, should also read
about L.
There is also: L.
=head1 Introduction
In the vast majority of cases, a perl Apache module that runs under
mod_perl 1.0 will B run under mod_perl 2.0 without at least some
degree of modification.
Even a very simple module that does not in itself need any changes
will at least need the mod_perl 2.0 Apache modules loaded, because in
mod_perl 2.0 basic functionality, such as access to the request object
and returning an HTTP status, is not found where, or implemented how
it used to be in mod_perl 1.0.
Most real-life modules will in fact need to deal with the following
changes:
=over
=item *
methods that have moved to a different (new) package
=item *
methods that must be called differently (due to changed prototypes)
=item *
methods that have ceased to exist (functionality provided in some
other way)
=back
B One way to deal with all of these issues is to
load the C>
compatibility layer bundled with mod_perl 2.0. This magic spell will
make almost any 1.0 module run under 2.0 without further changes. It
is by no means the solution for every case, however, so please read
carefully the following discussion of this and other options.
There are three basic options for porting. Let's take a quick look at
each one and then discuss each in more detail.
=over
=item 1 Run the module on 2.0 under C with no further changes
As we have said mod_perl 2.0 ships with a module,
C>, that provides a
complete drop-in compatibility layer for 1.0
modules. C does the following:
=over
=item *
Loads all the mod_perl 2.0 Apache2:: modules
=item *
Adjusts method calls where the prototype has changed
=item *
Provides Perl implementation for methods that no longer exist in 2.0
=back
The drawback to using C is the performance hit, which
can be significant.
Authors of CPAN and other publicly distributed modules should not use
C since this forces its use in environments where the
administrator may have chosen to optimize memory use by making all
code run natively under 2.0.
=item 2 Modify the module to run only under 2.0
If you are not interested in providing backwards compatibility with
mod_perl 1.0, or if you plan to leave your 1.0 module in place and
develop a new version compatible with 2.0, you will need to make
changes to your code. How significant or widespread the changes are
depends largely of course on your existing code.
Several sections of this document provide detailed information on how
to rewrite your code for mod_perl 2.0 Several tools are provided to
help you, and it should be a relatively painless task and one that you
only have to do once.
=item 3 Modify the module so that it runs under both 1.0 and 2.0
You need to do this if you want to keep the same version number for
your module, or if you distribute your module on CPAN and want to
maintain and release just one codebase.
This is a relatively simple enhancement of option (2) above. The module
tests to see which version of mod_perl is in use and then executes the
appropriate method call.
=back
The following sections provide more detailed information and
instructions for each of these three porting strategies.
=head1 Using C
META: to be written. this is a new package which makes chunks of this
doc simpler. for now see the
C> manpage.
=head1 Using the C Layer
The C> module tries
to hide the changes in API prototypes between version 1.0 and 2.0 of
mod_perl, and implements "virtual methods" for the methods and
functions that actually no longer exist.
C is extremely easy to use. Either add at the very
beginning of startup.pl:
use Apache2::compat;
or add to httpd.conf:
PerlModule Apache2::compat
That's all there is to it. Now you can run your 1.0 module unchanged.
Remember, however, that using C will make your module
run slower. It can create a larger memory footprint than you need and
it implements functionality in pure Perl that is provided in much
faster XS in mod_perl 1.0 as well as in 2.0. This module was really
designed to assist in the transition from 1.0 to 2.0. Generally you
will be better off if you port your code to use the mod_perl 2.0 API.
It's also especially important to repeat that C>, since this
takes the control over performance away from users.
=head1 Porting a Perl Module to Run under mod_perl 2.0
Note: API changes are listed in L.
The following sections will guide you through the steps of porting
your modules to mod_perl 2.0.
=head2 Using C to Discover Which mod_perl 2.0 Modules Need to Be Loaded
It would certainly be nice to have our mod_perl 1.0 code run on the
mod_perl 2.0 server unmodified. So first of all, try your luck and
test the code.
It's almost certain that your code won't work when you try, however,
because mod_perl 2.0 splits functionality across many more modules
than version 1.0 did, and you have to load these modules before the
methods that live in them can be used. So the first step is to figure
out which these modules are and C