Bric::Util::ApacheReq - Wrapper around Apache 1 and 2 Request classes


use Bric::Util::ApacheReq;
my $r = Bric::Util::ApacheReq->instance;


This package encapsulates the Apache::Request and Apache2::RequestUtil classes so that Bricolage doesn't have to care about which version of Apache is running. So instead of doing this:

use Bric::Config qw(MOD_PERL_VERSION);
    if (MOD_PERL_VERSION < 2) {
        require Apache;
        require Apache::Request;
    } else {
        require Apache2::Request::Util;
my $r = (MOD_PERL_VERSION < 2
    ? Apache::Request->instance(Apache->request)
    : Apache2::RequestUtil->request);

you do what's shown in the SYNOPSIS.

It also adds the server method from Apache or Apache2::ServerUtil, as appropriate.


Public Class Methods

my $req = Bric::Util::ApacheReq->request;

Returns either Apache->request for mod_perl 1 or Apache2::RequestUtil->request for mod_perl 2.

my $r = Bric::Util::ApacheReq->instance;

Returns the Apache request object, i.e. $r. Optionally takes the following argument:

my $server = Bric::Util::ApacheReq->server;

Returns either Apache->server for mod_perl 1 or Apache2::ServerUtil->server for mod_perl 2.

my $url = Bric::Util::ApacheReq->url();
my $url = Bric::Util::ApacheReq->url;
my $url = Bric::Util::ApacheReq->url( uri => '/foo/bar' );
my $url = Bric::Util::ApacheReq->url( ssl => 1 );

Returns a URL for the server, with the correct scheme (http or https), host name, and port (if needed). Pass in a url parameter (including a leading slash) to have a particular URI path included in the URL. If it's not passed, or is undef, it defaults to "/". If you're prefer to have SSL if it's enabled, pass in an ssl parameter with a true value.

Public Functions

my %args = parse_args(scalar $r->args);

In mod_perl, $r->args could be used in list context, to return a parsed hash of key => value, but in mod_perl2 it can only be used in scalar context. This implements the old behavior for mod_perl2 using parse_args from Apache2::compat. Always call $r->args in scalar context in Bricolage code, then use this function to parse the result if necessary.


Scott Lanning <>