Andy Wardley > Badger-0.09 > Badger::Factory::Class

Download:
Badger-0.09.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  1
View/Report Bugs
Source  

NAME ^

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

SYNOPSIS ^

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 );

DESCRIPTION ^

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.

METHODS ^

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

item($name)

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

items($name)

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

path($name)

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.

names($names)

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.

default($name)

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

AUTHOR ^

Andy Wardley http://wardley.org/

COPYRIGHT ^

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.

SEE ALSO ^

Badger::Factory, Badger::Codecs

syntax highlighting: