NAME

Krang::ClassFactory - a registry for class names allowing runtime overrides


SYNOPSIS

  use Krang::ClassLoader ClassFactory => qw(pkg);
  # instead of this
  pkg('Story')->new(...);
  # write this:
  pkg('Story')->new();


DESCRIPTION

This module mainatins a table of class names which allows addons to selectively override core Krang classes. AddOns declare their overrides via a conf/class.conf file. For example, if the Turbo-1.00.tar.gz addon contains a conf/class.conf file with:

  SetClass Story      Turbo::Story
  SetClass CGI::Story Turbo::CGI::Story

Then Krang will return 'Turbo::Story' for calls to pkg('Story') and 'Turbo::CGI::Story' for pkg('CGI::Story'). This will have the effect of dynamically substituting Turbo::Story for Krang::Story and Turbo::CGI::Story for Krang::Story. The benefit of this over just including lib/Krang/Story.pm in the addon is that Turbo's classes can (and probably should) inherit from Krang::Story and Krang::CGI::Story to implement its functionality.


INTERFACE

pkg($class_name)

This function returns a class name (ex. Krang::Story) given a partial class name (Story). By default this function meerly appends Krang:: to the name passed in, unless an addon has registered an override, in which case that will be returned instead.

The name for this function was chosen primarily for its size. Since pkg('foo') is exactly as long as Krang:: this new system was added via search-and-replace without breaking any code formatting.