DESCRIPTION

This distribution facilitates the run-time generation of classes which inherit from a base class and some optional selection of mixin classes.

A factory is provided to generate the mixed classes with multiple inheritance. A NEXT method allows method redispatch up the inheritance chain.

USAGE

The Class::MixinFactory package is just a facade that loads the necessary classes and provides a few import options for compile-time convenience.

Factory Interface

To generate an object with some combination of mixins, you first pass the names of the mixin classes to a class factory which will generate a mixed class. (Or return the name of the already generated class, if there has been a previous request with the same combination of mixins.)

You can add a factory method to your base class, create a separate factory object, or inherit to produce a factory class.

Factory Method

To add a factory method to a base class, inherit from the Class::MixinFactory::HasAFactory class, or use the -hasafactory import option:

Configuring a Factory

The mixin prefix is prepended to the mixin names passed to the class() method. Mixin names that contain a "::" are assumed to be fully qualified and are not changed. If empty, the base_class is used.

$factory->mixin_prefix( 'HelloFeature' );

The mixed prefix is at the start of all generated class names. If empty, the base_class is used, or the factory's class name.

$factory->mixed_prefix( 'HelloClass' );

Writing a Mixin Class

Writing a mixin class is almost the same as writing a subclass, except where methods need to redispatch to the base-class implementation. (The SUPER::method syntax will only search for classes that the mixin itself inherits from; to search back up the inheritance tree and explore other branches, another redispatch mechanism is needed.)

A method named NEXT is provided to continue the search through to the next class which provides a given method. The order in which mixins are stacked is significant, so the caller should understand how their behaviors interact. (See Class::MixinFactory::NEXT.)