The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

MooseX::Traitor - An alternate way to compose your classes with traits

VERSION

This document describes version 0.002 of MooseX::Traitor - released March 03, 2014 as part of MooseX-Util.

SYNOPSIS

    # in your class definition...
    package MyClass;
    use Moose;
    use namespace::autoclean;

    with 'MooseX::Traitor';

    # somewhere else in Gotham...
    my $thinger = MyClass->with_traits('Thinger::Trait1')->new(...);

DESCRIPTION

One of the most powerful things about Moose is that with roles and easy "anonymous" class creation we are blessed with a fantastic new way of creating classes, often on the fly, out of other classes and those composable bits of behaviour, roles.

Even better, this application of discrete chunks of behaviours enables people simply using a class to extend and tweak its behaviour in new ways -- possibly ways never contemplated by the authors of the classes being altered.

METHODS

with_traits(<trait1>, ...)

This method builds an anonymous class from the consuming class and any traits specified.

You may use the full trait specification syntax, e.g.:

    MyClass->with_traits('My::Trait' => { -excludes => ... })

Calling this routine with no traits specified will simply return the name of the class. This is not considered an error.

Note that we handle being called directly against a package (e.g. MyClass-with_traits(...)>) and against an instance (e.g. $self-with_traits(...)>) identically; in each instance the class referenced is subclassed.

ROLES OR TRAITS?

There are many different definitions of what a role is vs a trait, ranging from "hey man, it's all cool" to "CLOS calls them all traits SO TRAITS IS THE ONE TRUE NAME", it seems that most people tend to think of them this way:

Roles are traits that a class knowingly consumes (e.g. via with()).

Traits are roles that are applied without the class' consent (e.g. anonymous subclass composition or $trait_meta-apply('ClassThinger')>).

Or maybe that's just what this author is imposing on everyone else. Either way, that's what we'll be using here if the definition ever becomes important.

SEE ALSO

Please see those modules/websites for more information related to this module.

SOURCE

The development version is on github at http://github.com/RsrchBoy/moosex-util and may be cloned from git://github.com/RsrchBoy/moosex-util.git

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/RsrchBoy/moosex-util/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Chris Weyl <cweyl@alumni.drew.edu>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2012 by Chris Weyl.

This is free software, licensed under:

  The GNU Lesser General Public License, Version 2.1, February 1999