Scroll to navigation

MooseX::Role::TraitConstructor(3) User Contributed Perl Documentation MooseX::Role::TraitConstructor(3)

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

Returns the string "traits".

Override to rename the parameter.

A "new" in Moose::Object like parameter processor which will call "new" on the return value of "interpolate_class_from_params".
This method will automatically create an anonymous class with the roles from the "traits" param mixed into it if one exists.

If not the normal class name will be returned.

Will remove the "traits" parameter 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.

Calls "filter_constructor_traits" on the result of "resolve_constructor_traits".
Attempt to load the traits specified in @traits usinc "resolve_constructor_trait"
Attempts to get a processed name from "process_trait_name", and then tries to load that.

If "process_trait_name" didn't return a true value or its return value could not be loaded then $trait will be tried.

If nothing could be loaded an error is thrown.

$possible_root is the name of the first non anonymous class in the "linearized_isa", usually $class, but will DWIM in case $class has already been interpolated with traits from a named class.

Returns "join "::", $possible_root, $trait".

You probably want to override this method.

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.
2011-04-01 perl v5.38.2