NAME
MooseX::Role::ConstructorRoleApplication - apply roles right after construction
VERSION
Version 0.03
SYNOPSIS
package Foo;
use Moose;
with 'MooseX::Role::ConstructorRoleApplication';
# construct a Foo that also does My::Role and My::OtherRole
my $foo = Foo->new(apply => ['My::Role', 'My::OtherRole']);
DESCRIPTION
Adds the apply
argument to classes into which this role is composed. The value must be an array reference of names of roles to apply to the new instance.
It does not apply the roles to the class itself, so other instances may be constructed without the roles.
This role is similar in purpose to MooseX::Traits but composes roles into the class instance immediately after construction, rather than creating an anonymous class before the new object is instantiated.
The advantage of this module over MooseX::Traits
module is that role application is accomplished with a single call to new
. Use MooseX::Role::ConstructorRoleApplication
if you're a fan of Test::More's new_ok
or for other reasons require a single call to new
rather than a chain of calls (as would be necessary with MooseX::Traits
). Otherwise, use MooseX::Traits
.
# using MooseX::Role::ConstructorRoleApplication
my $obj = Class->new(apply=>['Role']);
# using MooseX::Traits
my $obj = Class->with_traits('Role')->new;
Of course, when using MooseX::Role::ConstructorRoleApplication
, you cannot supply to the constructor values for attributes provided by the role (or roles) that are yet to be applied. Such values must be set after the object is instantiated. Some mechanism to set role attributes may exist in a future version.
AUTHOR
Fraser Tweedale, <frasert at jumbolotteries.com>
BUGS
Please report any bugs or feature requests to bug-moosex-role-constructorroleapplication at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Role-ConstructorRoleApplication. 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::Role::ConstructorRoleApplication
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Role-ConstructorRoleApplication
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/MooseX-Role-ConstructorRoleApplication
CPAN Ratings
http://cpanratings.perl.org/d/MooseX-Role-ConstructorRoleApplication
Search CPAN
http://search.cpan.org/dist/MooseX-Role-ConstructorRoleApplication/
SEE ALSO
MooseX::Traits is a module similar in purpose that performs role performs role composition prior to, rather than after, instantiation. In most cases, a better choice than this module.
LICENSE AND COPYRIGHT
Copyright 2011 Benon Technologies Pty Ltd
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.