Take me over?
NAME
MooseX::Role::TraitConstructor - A wrapper for new that can accept a traits parameter.
SYNOPSIS
package Foo;
use Moose;
with qw(MooseX::Role::TraitConstructor);
package Foo::Bah;
sub bah_method { ... }
my $foo = Foo->new( traits => [qw( Bah )] );
$foo->bah_method;
DESCRIPTION
This role allows you to easily accept a traits argument (or another name) into your constructor, which will easily mix roles into an anonymous class before construction, much like Moose::Meta::Attribute does.
METHODS
- constructor_trait_param
-
Returns the string
traits.Override to rename the parameter.
- new_with_traits %params
- new_with_traits $params
-
A "new" in Moose::Object like parameter processor which will call
newon the return value ofinterpolate_class_from_params. - interpolate_class_from_params $params
-
This method will automatically create an anonymous class with the roles from the
traitsparam mixed into it if one exists.If not the normal class name will be returned.
Will remove the
traitsparameter from$params.Also works as an instance method, but always returns a class name.
In list context also returns the actual list of roles mixed into the class.
- process_constructor_traits $params, @traits
-
Calls
filter_constructor_traitson the result ofresolve_constructor_traits. - resolve_constructor_traits $params, @traits
-
Attempt to load the traits specified in
@traitsusincresolve_constructor_trait - guess_original_class_name $params
- resolve_constructor_trait $params, $possible_root, $trait
-
Attempts to get a processed name from
process_trait_name, and then tries to load that.If
process_trait_namedidn't return a true value or its return value could not be loaded then$traitwill be tried.If nothing could be loaded an error is thrown.
$possible_rootis the name of the first non anonymous class in thelinearized_isa, usually$class, but will DWIM in case$classhas already been interpolated with traits from a named class. - process_trait_name $trait, $params, $possible_root
-
Returns
join "::", $possible_root, $trait.You probably want to override this method.
- filter_constructor_traits $params, $traits,
-
Returns all the the roles that the invocant class doesn't already do (uses
does).
VERSION CONTROL
http://code2.0beta.co.uk/moose/svn/. Ask on #moose for commit bits.
AUTHOR
Yuval Kogman <nothingmuch@woobling.org>
COPYRIGHT
Copyright (c) 2008 Yuval Kogman. All rights reserved
This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.