Class::Accessor::FactoryTyped - accessors whose values come from a factory
package Person; use base 'Class::Accessor::FactoryTyped'; __PACKAGE__->mk_factory_typed_accessors( 'My::Factory', person_name => 'name', person_address => 'address', );
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.
This section describes the accessor makers offered by this module, and the methods it generates.
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.
Class::Accessor::Complex
mk_object_accessors()
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 parsed thus:
See baz() above. The hash should contain the following keys:
baz()
The name of the instance attribute (slot).
A string or array reference, naming the methods that will be forwarded directly to the object in the slot.
As for String, for each member of the array. Also works if each member is a hash reference (see fob() above).
String
fob()
For each slot x, with forwarding methods y() and z(), the following methods are created:
x
y()
z()
A get/set method, see * below.
*
Forwarded onto the object in slot x, which is auto-created via new() if necessary. The new(), if called, is called without arguments.
new()
As for y.
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.
foo()
foo
My::Factory
baz
bar()
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.
Like mk_factory_typed_accessors() except creates array accessors with all methods like those generated by Class::Accessor::Complex's mk_array_accessors().
mk_factory_typed_accessors()
mk_array_accessors()
TODO: More documentation is needed, but this is an early release.
If you talk about this module in blogs, on del.icio.us or anywhere else, please use the classaccessorfactorytyped tag.
classaccessorfactorytyped
No bugs have been reported.
Please report any bugs or feature requests to bug-class-accessor-factorytyped@rt.cpan.org, or through the web interface at http://rt.cpan.org.
bug-class-accessor-factorytyped@rt.cpan.org
See perlmodinstall for information and options on installing Perl modules.
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://www.perl.com/CPAN/authors/id/M/MA/MARCEL/>.
Marcel Grünauer, <marcel@cpan.org>
<marcel@cpan.org>
Copyright 2007 by Marcel Grünauer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Class::Accessor::FactoryTyped, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Class::Accessor::FactoryTyped
CPAN shell
perl -MCPAN -e shell install Class::Accessor::FactoryTyped
For more information on module installation, please visit the detailed CPAN module installation guide.