Dzil-ize all the .pod files so they can be pod-woven
[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
eec11834 18While most collisions can be avoided, you cannot avoid importing a
19C<meta> method when you C<S<use Moose>>. If you try to override or
20change what C<meta> does, you could end up breaking Moose internals.
4499a7ab 21
eec11834 22=head2 Moose Keywords
4499a7ab 23
eec11834 24If you are using L<Moose> or L<Moose::Role> its best to avoid these
47b19570 25keywords:
4499a7ab 26
27=over 4
28
eec11834 29=item extends
4499a7ab 30
eec11834 31=item with
4499a7ab 32
eec11834 33=item has
4499a7ab 34
eec11834 35=item before
4499a7ab 36
eec11834 37=item after
4499a7ab 38
eec11834 39=item around
4499a7ab 40
eec11834 41=item super
4499a7ab 42
eec11834 43=item override
4499a7ab 44
eec11834 45=item inner
4499a7ab 46
eec11834 47=item augment
4499a7ab 48
eec11834 49=item confess
4499a7ab 50
eec11834 51=item blessed
4499a7ab 52
53=back
54
eec11834 55=head2 Moose::Util::TypeConstraints Keywords
4499a7ab 56
eec11834 57If you are using L<Moose::Util::TypeConstraints> its best to avoid
58these keywords
4499a7ab 59
60=over 4
61
eec11834 62=item type
4499a7ab 63
eec11834 64=item subtype
4499a7ab 65
eec11834 66=item class_type
4499a7ab 67
eec11834 68=item role_type
4499a7ab 69
eec11834 70=item maybe_type
4499a7ab 71
eec11834 72=item as
4499a7ab 73
eec11834 74=item where
75
76=item message
4499a7ab 77
78=item optimize_as
79
eec11834 80=item coerce
4499a7ab 81
eec11834 82=item from
4499a7ab 83
84=item via
85
86=item enum
87
88=item find_type_constraint
89
90=item register_type_constraint
91
92=back
93
94=head2 Avoiding collisions
47b19570 95
4499a7ab 96=head3 Turning off Moose
97
eec11834 98To remove the sugar functions L<Moose> exports just add C<S<no Moose>>
99at the bottom of your code:
47b19570 100
101 package Thing;
102 use Moose;
4499a7ab 103
47b19570 104 # code here
4499a7ab 105
47b19570 106 no Moose;
4499a7ab 107
eec11834 108This will unexport the sugar functions that L<Moose> originally
109exported. The same will also work for L<Moose::Role> and
110L<Moose::Util::TypeConstraints>.
4499a7ab 111
eec11834 112=head3 Sub::Exporter features
4499a7ab 113
eec11834 114L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use
115L<Sub::Exporter> to handle all their exporting needs. This means that
116all the features that L<Sub::Exporter> provides are also available to
117them.
4499a7ab 118
47b19570 119For instance, with L<Sub::Exporter> you can rename keywords, like so:
4499a7ab 120
47b19570 121 package LOL::Cat;
122 use Moose 'has' => { -as => 'i_can_haz' };
eec11834 123
47b19570 124 i_can_haz 'cheeseburger' => (
eec11834 125 is => 'rw',
126 trigger => sub { print "NOM NOM" }
47b19570 127 );
eec11834 128
47b19570 129 LOL::Cat->new->cheeseburger('KTHNXBYE');
4499a7ab 130
47b19570 131See the L<Sub::Exporter> docs for more information.
4499a7ab 132
133=head3 namespace::clean
134
eec11834 135You can also use L<namespace::clean> to clean up your namespace, but
136you must be careful not to remove C<meta> when doing so:
47b19570 137
138 package Foo;
139 use Moose;
140 use namespace::clean -except => 'meta';
141 # ...
142
143=head1 SEE ALSO
144
145=over 4
146
147=item L<Moose>
4499a7ab 148
47b19570 149=item L<Moose::Role>
150
151=item L<Moose::Utils::TypeConstraints>
152
153=item L<Sub::Exporter>
154
155=item L<namespace::clean>
156
157=back
158
4499a7ab 159=cut