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 While most collisions can be avoided, you cannot avoid importing a
19 C<meta> method when you C<S<use Moose>>. If you try to override or
20 change what C<meta> does, you could end up breaking Moose internals.
24 If you are using L<Moose> or L<Moose::Role> its best to avoid these
55 =head2 Moose::Util::TypeConstraints Keywords
57 If you are using L<Moose::Util::TypeConstraints> its best to avoid
88 =item find_type_constraint
90 =item register_type_constraint
94 =head2 Avoiding collisions
96 =head3 Turning off Moose
98 To remove the sugar functions L<Moose> exports just add C<S<no Moose>>
99 at the bottom of your code:
108 This will unexport the sugar functions that L<Moose> originally
109 exported. The same will also work for L<Moose::Role> and
110 L<Moose::Util::TypeConstraints>.
112 =head3 Sub::Exporter features
114 L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use
115 L<Sub::Exporter> to handle all their exporting needs. This means that
116 all the features that L<Sub::Exporter> provides are also available to
119 For instance, with L<Sub::Exporter> you can rename keywords, like so:
122 use Moose 'has' => { -as => 'i_can_haz' };
124 i_can_haz 'cheeseburger' => (
126 trigger => sub { print "NOM NOM" }
129 LOL::Cat->new->cheeseburger('KTHNXBYE');
131 See the L<Sub::Exporter> docs for more information.
133 =head3 namespace::clean
135 You can also use L<namespace::clean> to clean up your namespace, but
136 you must be careful not to remove C<meta> when doing so:
140 use namespace::clean -except => 'meta';
151 =item L<Moose::Utils::TypeConstraints>
153 =item L<Sub::Exporter>
155 =item L<namespace::clean>