1 package Moose::Cookbook::Snack::Keywords;
3 # ABSTRACT: Restricted "keywords" in Moose
11 Moose exports a number of sugar functions in order to emulate Perl
12 built-in keywords. These can cause clashes with other user-defined
13 functions. This document provides a list of those keywords for easy
16 =head2 The 'meta' keyword
18 C<S<use Moose>> adds a method called C<meta> to your class. If this
19 conflicts with a method or function you are using, you can rename it,
20 or prevent it from being installed entirely. To do this, pass the
21 C<-meta_name> option when you C<S<use Moose>>. For instance:
23 # install it under a different name
24 use Moose -meta_name => 'moose_meta';
26 # don't install it at all
27 use Moose -meta_name => undef;
31 If you are using L<Moose> or L<Moose::Role> it is best to avoid these
62 =head2 Moose::Util::TypeConstraints Keywords
64 If you are using L<Moose::Util::TypeConstraints> it is best to avoid
99 =item find_type_constraint
101 =item register_type_constraint
105 =head2 Avoiding collisions
107 =head3 Turning off Moose
109 To remove the sugar functions L<Moose> exports, just add C<S<no Moose>>
110 at the bottom of your code:
119 This will unexport the sugar functions that L<Moose> originally
120 exported. The same will also work for L<Moose::Role> and
121 L<Moose::Util::TypeConstraints>.
123 =head3 Sub::Exporter features
125 L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use
126 L<Sub::Exporter> to handle all their exporting needs. This means that
127 all the features that L<Sub::Exporter> provides are also available to
130 For instance, with L<Sub::Exporter> you can rename keywords, like so:
133 use Moose 'has' => { -as => 'i_can_haz' };
135 i_can_haz 'cheeseburger' => (
137 trigger => sub { print "NOM NOM" }
140 LOL::Cat->new->cheeseburger('KTHNXBYE');
142 See the L<Sub::Exporter> docs for more information.
144 =head3 namespace::autoclean and namespace::clean
146 You can also use L<namespace::autoclean> to clean up your namespace.
147 This will remove all imported functions from your namespace. Note
148 that if you are importing functions that are intended to be used as
149 methods (this includes L<overload>, due to internal implementation
150 details), it will remove these as well.
152 Another option is to use L<namespace::clean> directly, but
153 you must be careful not to remove C<meta> when doing so:
157 use namespace::clean -except => 'meta';
168 =item L<Moose::Utils::TypeConstraints>
170 =item L<Sub::Exporter>
172 =item L<namespace::autoclean>
174 =item L<namespace::clean>