NAME
MooseX::Attribute::Prototype - Borrow and Extend Moose Attrtibutes
VERSION
0.03 - Released 2009-01-26
SYNOPSIS
package MyClass;
use Moose;
use MooseX::Attribute::Prototype;
has 'my_attr' => (
is => 'rw' ,
isa => 'Str' ,
prototype => 'MyRole/MyAttr' ,
);
DESCRIPTION
This module loads a metaclass role that supports attribute prototyping, the practice of borrowing and (possibly) extending/overriding a predefined attributes. It works much like extending a class.
When you have a prototype in your attribute definition, you borrow the settings from the prototype. In many situations, this is all you will need. But sometimes you want to tweak beahaviors and/or defaults. MooseX::Attribute::Prototype allows the defaults to be overridden with those defined in the class. The resulting attribute specification is installed in the class.
How to use Attribute Prototypes
Prototypes are just any ole attributes in any ole Moose::Role. To use them simply specify the prototype
in your attribute definitions:
prototype => 'role/attribute'
where c<role> is the name of the role and c<attribute> is the name of the attribute.
WHY?
MooseX::Role::Parameterized and MooseX::Types abstract the roles and types, respectively. But surprisinly, there is no similar functionality for attributes. Moose leans towards viewing attributes as containers for data. However, it also provides the ability to store full-blown objects. And as they become more complex the can become unweildy. In fact, the attribute specifications, can often become the majority of code for a given application. Why not seperate these attributes into horizontally-reusable roles?
MooseX::Attribute::Prototype takes a functional view of attributes -- slots that can contain anything -- and provides an easy interface for making these slots reusable.
Why Not Moose's Attribute Clone Mechanism?
Moose's attribute cloning does not allow you to change the name of the derived attribute. You can take the defaults of an attribute from a role and change it's default, but good luck in changing the name of the attribute.
Subclassing Benefit
Moose makes subclassing easy through the c<extends> sugar. More often than not, however, Moose applications are an amalgam of objects including other Moose classes and other CPAN modules. In these cases, one often places the objects in the the attributes. MooseX::Attributes::Prototypes allows for the Moosifying of these CPAN classes in a reusable way.
SEE ALSO
MooseX::Attribute::Prototype::Meta,
MooseX::Attribute::Prototype::Object,
MooseX::Attribute::Prototype::Collection,
AUTHOR
Christopher Brown, <ctbrown at cpan.org>
BUGS
Please report any bugs or feature requests to bug-moosex-attribute-prototype at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Attribute-Prototype. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MooseX::Attribute::Prototype
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-Prototype
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Though they would probably cringe to hear it, this effort would not have been possible without:
Shawn Moore
David Rolsky
Thomas Doran
Stevan Little
COPYRIGHT & LICENSE
Copyright 2008 Christopher Brown and Open Data Group http://opendatagroup.com.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.