mod_perl logo perl icon
previous page: ModPerl::RegistryBB - Run unaltered CGI scripts persistently under mod_perlpage up: mod_perl 2.0 APInext page: ModPerl::RegistryLoader - Compile ModPerl::RegistryCooker scripts at server startup

ModPerl::RegistryCooker - Cook mod_perl 2.0 Registry Modules






mod_perl2 User's Guide

mod_perl2 User's Guide

By Stas Bekman, Jim Brandt
Practical mod_perl

Practical mod_perl

By Stas Bekman, Eric Cholet
The mod_perl Developer's Cookbook

The mod_perl Developer's Cookbook

By Geoffrey Young, Paul Lindner, Randy Kobes
mod_perl Pocket Reference

mod_perl Pocket Reference

By Andrew Ford
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


Table of Contents

Synopsis

  # shouldn't be used as-is but sub-classed first
  # see ModPerl::Registry for an example


TOP

Description

ModPerl::RegistryCooker is used to create flexible and overridable registry modules which emulate mod_cgi for Perl scripts. The concepts are discussed in the manpage of the following modules: ModPerl::Registry, ModPerl::Registry and ModPerl::RegistryBB.

ModPerl::RegistryCooker has two purposes:

Here are the current overridable methods:

META: these are all documented in RegistryCooker.pm, though not using pod. please help to port these to pod and move the descriptions here.



TOP

Special Predefined Functions

The following functions are implemented as constants.



TOP

Sub-classing Techniques

To override the default ModPerl::RegistryCooker methods, first, sub-class ModPerl::RegistryCooker or one of its existing sub-classes, using use base. Second, override the methods.

Those methods that weren't overridden will be resolved at run time when used for the first time and cached for the future requests. One way to to shortcut this first run resolution is to use the symbol aliasing feature. For example to alias ModPerl::MyRegistry::flush_namespace as ModPerl::RegistryCooker::flush_namespace, you can do:

  package ModPerl::MyRegistry;
  use base qw(ModPerl::RegistryCooker);
  *ModPerl::MyRegistry::flush_namespace =
      \&ModPerl::RegistryCooker::flush_namespace;
  1;

In fact, it's a good idea to explicitly alias all the methods so you know exactly what functions are used, rather then relying on the defaults. For that purpose ModPerl::RegistryCooker class method install_aliases() can be used. Simply prepare a hash with method names in the current package as keys and corresponding fully qualified methods to be aliased for as values and pass it to install_aliases(). Continuing our example we could do:

  package ModPerl::MyRegistry;
  use base qw(ModPerl::RegistryCooker);
  my %aliases = (
      flush_namespace => 'ModPerl::RegistryCooker::flush_namespace',
  );
  __PACKAGE__->install_aliases(\%aliases);
  1;

The values use fully qualified packages so you can mix methods from different classes.



TOP

Examples

The best examples are existing core registry modules: ModPerl::Registry, ModPerl::Registry and ModPerl::RegistryBB. Look at the source code and their manpages to see how they subclass ModPerl::RegistryCooker.

For example by default ModPerl::Registry uses the script's path when creating a package's namespace. If for example you want to use a uri instead you can override it with:

  *ModPerl::MyRegistry::namespace_from =
      \&ModPerl::RegistryCooker::namespace_from_uri;
  1;

Since the namespace_from_uri component already exists in ModPerl::RegistryCooker. If you want to write your own method, e.g., that creates a namespace based on the inode, you can do:

  sub namespace_from_inode {
      my $self = shift;
      return (stat $self->[FILENAME])[1];
  }

META: when $r->finfo will be ported it'll be more effecient. (stat $r->finfo)[1]



TOP

Authors

Doug MacEachern

Stas Bekman



TOP

See Also

ModPerl::Registry, ModPerl::RegistryBB and ModPerl::PerlRun.






TOP
previous page: ModPerl::RegistryBB - Run unaltered CGI scripts persistently under mod_perlpage up: mod_perl 2.0 APInext page: ModPerl::RegistryLoader - Compile ModPerl::RegistryCooker scripts at server startup