From: Dave Rolsky Date: Tue, 12 Aug 2008 16:36:29 +0000 (+0000) Subject: Documented metaclass traits, and moved trait name resolution to a X-Git-Tag: 0_55_01~38 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54f2996d6c6fd8794f53f9ce1f917ccfe2f1010a;p=gitmo%2FMoose.git Documented metaclass traits, and moved trait name resolution to a separate section in the docs so that it can describe the mechanism for both attribute & class traits. --- diff --git a/lib/Moose.pm b/lib/Moose.pm index 45ff77c..2b5a079 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -521,16 +521,13 @@ B as the metaclass name. This tells Moose to take the list of C<@role_names> and apply them to the attribute meta-object. This is very similar to the I option, but -allows you to use more than one extension at a time. This too is an advanced -topic, we don't yet have a cookbook for it though. +allows you to use more than one extension at a time. -As with I, the default behavior is to just load C<$role_name>; however, -we also have a way to alias to a shorter name. This will first look to see if -B exists. If it does, Moose -will then check to see if that has the method C, which -should return the actual name of the custom attribute trait. If there is no -C method, it will fall back to using -B as the trait name. +See L for details on how a trait name is +resolved to a class name. + +Also see L for a metaclass trait +example. =back @@ -690,6 +687,36 @@ C anywhere you need to test for an object's class name. =back +=head1 METACLASS TRAITS + +When you use Moose, you can also specify traits which will be applied +to your metaclass: + + use Moose -traits => 'My::Trait'; + +This is very similar to the attribute traits feature. When you do +this, your class's C object will have the specified traits +applied to it. See L for more details. + +=head1 TRAIT NAME RESOLUTION + +By default, when given a trait name, Moose simply tries to load a +class of the same name. If such a class does not exist, it then looks +for for a class matching +B. The C<$type> +variable here will be one of B or B, depending on +what the trait is being applied to. + +If a class with this long name exists, Moose checks to see if it has +the method C. This method is expected to +return the I class name of the trait. If there is no +C method, it will fall back to using +B as the trait name. + +If all this is confusing, take a look at +L, which demonstrates how to create an +attribute trait. + =head1 UNIMPORTING FUNCTIONS =head2 B