minor doc fixes
[gitmo/Moose.git] / lib / Moose / Cookbook / Snack / Keywords.pod
CommitLineData
daa0fd7d 1package Moose::Cookbook::Snack::Keywords;
2
3# ABSTRACT: Restricted "keywords" in Moose
4499a7ab 4
daa0fd7d 5__END__
4499a7ab 6
daa0fd7d 7=pod
4499a7ab 8
4499a7ab 9=head1 DESCRIPTION
10
eec11834 11Moose exports a number of sugar functions in order to emulate Perl
12built-in keywords. These can cause clashes with other user-defined
13functions. This document provides a list of those keywords for easy
14reference.
4499a7ab 15
16=head2 The 'meta' keyword
17
c15484e6 18C<S<use Moose>> adds a method called C<meta> to your class. If this
19conflicts with a method or function you are using, you can rename it,
20or prevent it from being installed entirely. To do this, pass the
21C<-meta_name> option when you C<S<use Moose>>. For instance:
22
23 # install it under a different name
24 use Moose -meta_name => 'moose_meta';
25
26 # don't install it at all
27 use Moose -meta_name => undef;
4499a7ab 28
eec11834 29=head2 Moose Keywords
4499a7ab 30
740072ae 31If you are using L<Moose> or L<Moose::Role> it is best to avoid these
47b19570 32keywords:
4499a7ab 33
34=over 4
35
eec11834 36=item extends
4499a7ab 37
eec11834 38=item with
4499a7ab 39
eec11834 40=item has
4499a7ab 41
eec11834 42=item before
4499a7ab 43
eec11834 44=item after
4499a7ab 45
eec11834 46=item around
4499a7ab 47
eec11834 48=item super
4499a7ab 49
eec11834 50=item override
4499a7ab 51
eec11834 52=item inner
4499a7ab 53
eec11834 54=item augment
4499a7ab 55
eec11834 56=item confess
4499a7ab 57
eec11834 58=item blessed
4499a7ab 59
60=back
61
eec11834 62=head2 Moose::Util::TypeConstraints Keywords
4499a7ab 63
740072ae 64If you are using L<Moose::Util::TypeConstraints> it is best to avoid
65these keywords:
4499a7ab 66
67=over 4
68
eec11834 69=item type
4499a7ab 70
eec11834 71=item subtype
4499a7ab 72
eec11834 73=item class_type
4499a7ab 74
eec11834 75=item role_type
4499a7ab 76
eec11834 77=item maybe_type
4499a7ab 78
c15484e6 79=item duck_type
80
eec11834 81=item as
4499a7ab 82
eec11834 83=item where
84
85=item message
4499a7ab 86
87=item optimize_as
88
c15484e6 89=item inline_as
90
eec11834 91=item coerce
4499a7ab 92
eec11834 93=item from
4499a7ab 94
95=item via
96
97=item enum
98
99=item find_type_constraint
100
101=item register_type_constraint
102
103=back
104
105=head2 Avoiding collisions
47b19570 106
4499a7ab 107=head3 Turning off Moose
108
740072ae 109To remove the sugar functions L<Moose> exports, just add C<S<no Moose>>
eec11834 110at the bottom of your code:
47b19570 111
112 package Thing;
113 use Moose;
4499a7ab 114
47b19570 115 # code here
4499a7ab 116
47b19570 117 no Moose;
4499a7ab 118
eec11834 119This will unexport the sugar functions that L<Moose> originally
120exported. The same will also work for L<Moose::Role> and
121L<Moose::Util::TypeConstraints>.
4499a7ab 122
eec11834 123=head3 Sub::Exporter features
4499a7ab 124
eec11834 125L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use
126L<Sub::Exporter> to handle all their exporting needs. This means that
127all the features that L<Sub::Exporter> provides are also available to
128them.
4499a7ab 129
47b19570 130For instance, with L<Sub::Exporter> you can rename keywords, like so:
4499a7ab 131
47b19570 132 package LOL::Cat;
133 use Moose 'has' => { -as => 'i_can_haz' };
eec11834 134
47b19570 135 i_can_haz 'cheeseburger' => (
eec11834 136 is => 'rw',
137 trigger => sub { print "NOM NOM" }
47b19570 138 );
eec11834 139
47b19570 140 LOL::Cat->new->cheeseburger('KTHNXBYE');
4499a7ab 141
47b19570 142See the L<Sub::Exporter> docs for more information.
4499a7ab 143
c15484e6 144=head3 namespace::autoclean and namespace::clean
145
146You can also use L<namespace::autoclean> to clean up your namespace.
147This will remove all imported functions from your namespace. Note
148that if you are importing functions that are intended to be used as
149methods (this includes L<overload>, due to internal implementation
150details), it will remove these as well.
4499a7ab 151
c15484e6 152Another option is to use L<namespace::clean> directly, but
eec11834 153you must be careful not to remove C<meta> when doing so:
47b19570 154
155 package Foo;
156 use Moose;
157 use namespace::clean -except => 'meta';
158 # ...
159
160=head1 SEE ALSO
161
162=over 4
163
164=item L<Moose>
4499a7ab 165
47b19570 166=item L<Moose::Role>
167
168=item L<Moose::Utils::TypeConstraints>
169
170=item L<Sub::Exporter>
171
c15484e6 172=item L<namespace::autoclean>
173
47b19570 174=item L<namespace::clean>
175
176=back
177
4499a7ab 178=cut