Top Close Open

Badger::Factory::Class - class module for Badger::Factory sub-classes


Top Close Open

This module can be used to create subclasses of Badger::Factory.

package My::Widgets;

use Badger::Factory::Class
    version => 0.01,
    item    => 'widget',
    path    => 'My::Widget Your::Widget',
    widgets => {
        extra => 'Another::Widget::Module',
        super => 'Golly::Gosh',
    names   => {
        html  => 'HTML',
        color => 'Colour',

package main;

# class method
my $widget = My::Widgets->widget( foo => @args );

# object method
my $widgets = My::Widgets->new;
my $widget  = $widgets->widget( foo => @args );


Top Close Open

This module is a subclass of Badger::Class specialised for the purpose of creating Badger::Factory subclasses. It is used by the Badger::Codecs module among others.


Top Close Open

The following methods are provided in addition to those inherited from the Badger::Class base class.


Top Close Open

The singular name of the item that the factory manages. This is used to set the $ITEM package variable for Badger::Factory to use.


Top Close Open

The plural name of the item that the factory manages. This is used to set the $ITEMS package variable for Badger::Factory to use.


Top Close Open

A list of module names that form the search path when loading modules. This will set the relevant package variable depending on the value of $ITEMS (or the regular plural form of $ITEM if $ITEMS is undefined). For example, is $ITEMS is set to widgets then this method will set $WIDGETS_PATH.

You can specify the path as a reference to a list of module bases, e.g.

use Badger::Factory::Class
    item => 'widget',
    path => ['My::Widget', 'Your::Widget'];

Or as a single string containing multiple values separated by whitespace.

use Badger::Factory::Class
    item => 'widget',
    path => 'My::Widget Your::Widget';

If you specify it as a single string then you can also include optional and/or alternate parts in parentheses. For example the above can be written more concisely as:

use Badger::Factory::Class
    item => 'widget',
    path => '(My|Your)::Widget';

If the parentheses don't contain a vertical bar then then enclosed fragment is treated as being optional. So instead of writing something like:

use Badger::Factory::Class
    item => 'widget',
    path => 'Badger::Widget BadgerX::Widget';

You can write:

use Badger::Factory::Class
    item => 'widget',
    path => 'Badger(X)::Widget';

See the permute_fragments() function in Badger::Utils for further details on how fragments are expanded.


Top Close Open

A reference to a hash array of name mappings. This can be used to handle any unusual spellings or capitalisations. See Badger::Factory for further details.


Top Close Open

The default name to use when none is specified in a request for a module.


Top Close Open

Andy Wardley


Top Close Open

Copyright (C) 2006-2009 Andy Wardley. All Rights Reserved.

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

Fork Me on Github