ModPerl::ParamBuilder 0.08 review

Download
by rbytes.net on

ModPerl::ParamBuilder is a Perl module that makes building custom Apache directives easy. SYNOPSIS package MyApp::Parameters

License: Perl Artistic License
File size: 8K
Developer: Frank Wiles
0 stars award from rbytes.net

ModPerl::ParamBuilder is a Perl module that makes building custom Apache directives easy.

SYNOPSIS

package MyApp::Parameters;

use ModPerl::ParamBuilder;

use base qw( 'ModPerl::ParamBuilder' );

my $builder = ModPerl::ParamBuilder->new( __PACKAGE__ );

# Build simple one argument parameter
$builder->param( 'Template' );
$builder->param( 'PageTitle' );
$builder->param( 'ItemsPerPage' );

# Build an On/Off parameter
$builder->on_off( 'Caching' );

# Build a Yes/No parameter
$builder->yes_no( 'AutoCommit' );

# Build a no argument/flag parameter
$builder->no_arg( 'Active' );

# Build a one argument parameter with a custom error message
# and special configuration hash key
$builder->param( {
name => 'SMTPServer',
err => 'SMTPServer xx.xx.xx.xx',
key => 'smtp_server',
});

# Load the configuration into Apache
$builder->load;

################################################
# And elsewhere in your application
################################################
package MyApp::Main;

# Retrieve the configuration like so
my $params = MyApp::Parameters->new;
my $conf_ref = $params->get_config( $r );

# Or if you have PerlOptions +GlobalRequest on then you can just
# call
my $conf_ref = $params->get_config;

One of the neatest features of mod_perl 2.0 is the ability to easily create your own custom Apache directives. Not only are they more efficient to use compared to PerlSetEnv, PerlPassEnv, PerlAddVar, and PerlSetVar, but they give your application a more polished and professional look and feel..

Not to mention they're just plain cool. This module aims to make the already easy, even easier.
Note that you MUST load your parameter module with PerlLoadModule in your httpd.conf and not PerlModule. This is necessary because Apache needs to load your module earlier than usual in the startup to be able to read it's own configuration now.

LIMITATIONS

The biggest limitation is that this module ONLY works with mod_perl 2.0 and above. There are no plans to support mod_perl 1.x for this module, trust me you want to upgrade to mod_perl 2 as soon as you can.

This module's intent is not to replace the underlying mod_perl APIs nor is it intended to be used for complicated cases where special processing is needed. It is intended to make the simple things simple.

Some things to keep in mind when using ModPerl::ParamBuilder

This module does not restrict where the directives can be used in Apache's httpd.conf. To restrict directives to particular area ( only in main server conf, a VirtualHost, or a Location, etc ) you will need to use the mod_perl APIs to build your directives.

This also does not do, by default, any error checking or validation on the arguments passed to directives. If you create a directive 'NumberOfItemsPerPage' and then put:

NumberOfItemsPerPage rhubarb

Apache will not see this as an error and your configuration hash for the key 'NumberOfItemsPerPage' will contain the string 'rhubarb'. You can validate this data in three different ways:

1) Validate the configuration data in your application prior to
using it.

2) Instruct ModPerl::ParamBuilder to use a special function for
processing the arguments by passing the 'func' option.

3) Revert to using the mod_perl API where you have more control.

See the appropriate mod_perl 2.0 API modules for how to accomplish more in depth processing of directives and their data.

Requirements:
Perl

ModPerl::ParamBuilder 0.08 search tags