Class::Factory - Base class for dynamic factory classes

package My::Factory;

use strict;
use base qw( Class::Factory );

# Add our default types

My::Factory->add_factory_type( perl => 'My::Factory::Perl' ); My::Factory->add_factory_type( blech => 'My::Factory::Blech' );

# Register optional types

My::Factory->register_factory_type( java => 'My::Factory::Java' );

1;

# Create new objects using the default types

my $perl_item = My::Factory->new( 'perl', foo => 'bar' ); my $blech_item = My::Factory->new( 'blech', foo => 'baz' );

# Create new object using the optional type; this library is loaded # on the first use

my $java_item = My::Factory->new( 'java', foo => 'quux' );

# Adding a new factory type in code

My::Factory->add_factory_type( custom => 'Other::Custom::Class' ); my $custom_object = My::Factory->new( 'custom', this => 'that' );

# Register a new factory type in code

My::Factory->register_factory_type( bleededge => 'Other::Customized::Class' ); my $edgy_object = My::Factory->new( 'bleededge', this => 'that' );

# Get a registered class name given it's factory type

my $registered_class = MyFactory->get_registered_class( 'bleededge' );

# Remove a factory type

MyFactory->remove_factory_type('custom');

# Unregister a factory type

MyFactory->unregister_factory_type('bleededge');

See POD for details

INSTALLATION

To install this module perform the typical four-part Perl salute:

perl Makefile.PL
make
make test
make install

DEPENDENCIES

None, although this module was written almost entirely under the influence of Weezer.

get_registered_class() was written under the influence of Phix.

SIDE-EFFECTS

May include headache, insomnia, and growth spurts, although a control group given English toffees in place had the same effects.

COPYRIGHT AND LICENCE

Copyright (c) 2002-2007 Chris Winters. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHORS

Fred Moyer <fred@redhotpenguin.com> is the current maintainer.

Chris Winters <chris@cwinters.com> is the author of Class::Factory.

Eric Andreychek <eric@openthought.net> also helped out with code, testing and good advice.

Srdjan Jankovic <srdjan@catalyst.net.nz> contributed the idea for 'get_my_factory()' and 'get_my_factory_type()'

Sebastian Knapp <giftnuss@netscape.net> contributed the idea for 'get_registered_class()'

Marcel Gruenauer <marcel@cpan.org> contributed the methods remove_factory_type() and unregister_factory_type().