NAME

Class::Accessor::FactoryTyped - Accessors whose values come from a factory

VERSION

version 1.100970

SYNOPSIS

    package Person;
    use base 'Class::Accessor::FactoryTyped';

    __PACKAGE__->mk_factory_typed_accessors(
        'My::Factory',
        person_name    => 'name',
        person_address => 'address',
    );

DESCRIPTION

This module generates accessors for your class in the same spirit as Class::Accessor does. While the latter deals with accessors for scalar values, this module provides accessor makers for arrays, hashes, integers, booleans, sets and more.

As seen in the synopsis, you can chain calls to the accessor makers. Also, because this module inherits from Class::Accessor, you can put a call to one of its accessor makers at the end of the chain.

The accessor generators also generate documentation ready to be used with Sub::Documentation.

METHODS

mk_factory_typed_accessors

    MyClass->mk_factory_typed_accessors(
        'My::Factory',
        foo => 'phooey',
        bar => [ qw(bar1 bar2 bar3) ],
        baz => {
            slot => 'foo',
            comp_mthds => [ qw(bar baz) ]
        },
        fob => [
            {
                slot       => 'dog',
                comp_mthds => 'bark',
            },
            {
                slot       => 'cat',
                comp_mthds => 'miaow',
            },
        ],
    );

This behaves a lot like Class::Accessor::Complex's mk_object_accessors(), but the types of objects - that is, their class names - that the generated accessors can take aren't given statically, but are determined by asking a factory.

The factory class name must be the first argument. The class indicated should be a subclass of Class::Factory::Enhanced.

The following argument is an array which should contain pairs of class => sub-argument pairs. The sub-arguments are parsed like this:

Hash Reference

See baz() above. The hash should contain the following keys:

slot

The name of the instance attribute (slot).

comp_mthds

A string or array reference, naming the methods that will be forwarded directly to the object in the slot.

Array Reference

As for String, for each member of the array. Also works if each member is a hash reference (see fob() above).

String

The name of the instance attribute (slot).

For each slot x, with forwarding methods y() and z(), the following methods are created:

x

A get/set method, see * below.

y

Forwarded onto the object in slot x, which is auto-created via new() if necessary. The new(), if called, is called without arguments.

z

As for y.

So, using the example above, a method, foo(), is created, which can get and set the value of those objects in slot foo, which will generally contain an object of the type the factory, in this case My::Factory, uses for the object type baz. Two additional methods are created named bar() and baz() which result in a call to the bar() and baz() methods on the Baz object stored in slot foo.

Apart from the forwarding methods described above, mk_object_accessors() creates methods as described below, where * denotes the slot name.

*

If the accessor is supplied with an object of an appropriate type, will set set the slot to that value. Else, if the slot has no value, then an object is created by calling new() on the appropriate class, passing in any supplied arguments.

The stored object is then returned.

*_clear, clear_*

Removes the object from the accessor.

mk_factory_typed_array_accessors

Like mk_factory_typed_accessors() except creates array accessors with all methods like those generated by Class::Accessor::Complex's mk_array_accessors().

INSTALLATION

See perlmodinstall for information and options on installing Perl modules.

BUGS AND LIMITATIONS

No bugs have been reported.

Please report any bugs or feature requests through the web interface at http://rt.cpan.org/Public/Dist/Display.html?Name=Class-Accessor-FactoryTyped.

AVAILABILITY

The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit http://www.perl.com/CPAN/ to find a CPAN site near you, or see http://search.cpan.org/dist/Class-Accessor-FactoryTyped/.

The development version lives at http://github.com/hanekomu/Class-Accessor-FactoryTyped/. Instead of sending patches, please fork this project using the standard git and github infrastructure.

AUTHOR

  Marcel Gruenauer <marcel@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2007 by Marcel Gruenauer.

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