5 Moose::Cookbook::Snack::Keywords - Restricted "keywords" in Moose
9 Moose exports a number of sugar functions in order to emulate Perl
10 built-in keywords. These can cause clashes with other user-defined
11 functions. This document provides a list of those keywords for easy
14 =head2 The 'meta' keyword
16 While most collisions can be avoided, you cannot avoid importing a
17 C<meta> method when you C<S<use Moose>>. If you try to override or
18 change what C<meta> does, you could end up breaking Moose internals.
22 If you are using L<Moose> or L<Moose::Role> its best to avoid these
53 =head2 Moose::Util::TypeConstraints Keywords
55 If you are using L<Moose::Util::TypeConstraints> its best to avoid
86 =item find_type_constraint
88 =item register_type_constraint
92 =head2 Avoiding collisions
94 =head3 Turning off Moose
96 To remove the sugar functions L<Moose> exports just add C<S<no Moose>>
97 at the bottom of your code:
106 This will unexport the sugar functions that L<Moose> originally
107 exported. The same will also work for L<Moose::Role> and
108 L<Moose::Util::TypeConstraints>.
110 =head3 Sub::Exporter features
112 L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use
113 L<Sub::Exporter> to handle all their exporting needs. This means that
114 all the features that L<Sub::Exporter> provides are also available to
117 For instance, with L<Sub::Exporter> you can rename keywords, like so:
120 use Moose 'has' => { -as => 'i_can_haz' };
122 i_can_haz 'cheeseburger' => (
124 trigger => sub { print "NOM NOM" }
127 LOL::Cat->new->cheeseburger('KTHNXBYE');
129 See the L<Sub::Exporter> docs for more information.
131 =head3 namespace::clean
133 You can also use L<namespace::clean> to clean up your namespace, but
134 you must be careful not to remove C<meta> when doing so:
138 use namespace::clean -except => 'meta';
149 =item L<Moose::Utils::TypeConstraints>
151 =item L<Sub::Exporter>
153 =item L<namespace::clean>
159 John Goulah C<E<lt>jgoulah@cpan.org<gt>>
161 Stevan Little E<lt>stevan@iinteractive.comE<gt>
163 =head1 COPYRIGHT AND LICENSE
165 Copyright 2006-2009 by Infinity Interactive, Inc.
167 L<http://www.iinteractive.com>
169 This library is free software; you can redistribute it and/or modify
170 it under the same terms as Perl itself.