a5e9ddbc19db5cbc708933a45a199926741514d7
[gitmo/Moose.git] / lib / Moose / Cookbook / Snack / Keywords.pod
1 =pod
2
3 =head1 NAME
4
5 Moose::Cookbook::Snack::Keywords - Restricted keywords in Moose 
6
7 =head1 DESCRIPTION
8
9 There are several keywords exported by L<Moose> that can cause clashes 
10 against other user-defined barewords. The following document provides 
11 a list of those keywords in a single place for easy reference.
12
13 =head2 The 'meta' keyword
14
15 While most of the reserved keywords collisions can be avoided, however 
16 I<meta> is the only one you B<can not> override. Do not attempt to override
17 I<meta>, it will break the Moose internals.
18
19 =head2 Moose Keywords 
20
21 If you are using L<Moose> or L<Moose::Role> its best to avoid these 
22 keywords:
23
24 =over 4
25
26 =item extends 
27
28 =item with 
29
30 =item has 
31
32 =item before 
33
34 =item after 
35
36 =item around 
37
38 =item super 
39
40 =item override 
41
42 =item inner 
43
44 =item augment 
45
46 =item make_immutable 
47
48 =item confess 
49
50 =item blessed 
51
52 =back
53
54 =head2 Moose::Util::TypeConstraints Keywords 
55
56 If you are using L<Moose::Util::TypeConstraints> its best to avoid 
57 these keywords 
58
59 =over 4
60
61 =item type 
62
63 =item subtype 
64
65 =item class_type 
66
67 =item role_type 
68
69 =item as 
70
71 =item where 
72
73 =item message 
74
75 =item optimize_as
76
77 =item coerce 
78
79 =item from 
80
81 =item via
82
83 =item enum
84
85 =item find_type_constraint
86
87 =item register_type_constraint
88
89 =back
90
91 =head2 Avoiding collisions
92
93 =head3 Turning off Moose
94
95 To remove the keywords L<Moose> exports just add C<no Moose> at the bottom of 
96 your code, like so:
97
98   package Thing;
99   use Moose;
100
101   # code here
102
103   no Moose;
104
105 This will un-export the keywords that L<Moose> originally exported. The same 
106 will also work for L<Moose::Role> and L<Moose::Util::TypeConstraints>. It is 
107 general L<Moose> policy that this feature is used.
108
109 =head3  Sub::Exporter
110
111 L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use 
112 L<Sub::Exporter> to handle all their exporting needs. This means that all the 
113 features that L<Sub::Exporter> provides are also available to them. 
114
115 For instance, with L<Sub::Exporter> you can rename keywords, like so:
116
117   package LOL::Cat;
118   use Moose 'has' => { -as => 'i_can_haz' };
119   
120   i_can_haz 'cheeseburger' => (
121      is      => 'rw',
122      trigger => sub { print "NOM NOM" }
123   );
124   
125   LOL::Cat->new->cheeseburger('KTHNXBYE');
126
127 See the L<Sub::Exporter> docs for more information.
128
129 =head3 namespace::clean
130
131 You can also use L<namespace::clean> to clean up your namespace, but you must 
132 be careful not to remove C<meta> with this. Here is an example of that usage:
133
134   package Foo;
135   use Moose;
136   use namespace::clean -except => 'meta';
137   # ...
138
139 =head1 SEE ALSO
140
141 =over 4
142
143 =item L<Moose>
144
145 =item L<Moose::Role>
146
147 =item L<Moose::Utils::TypeConstraints>
148
149 =item L<Sub::Exporter>
150
151 =item L<namespace::clean>
152
153 =back
154
155 =head1 AUTHOR
156
157 John Goulah C<E<lt>jgoulah@cpan.org<gt>>
158
159 Stevan Little E<lt>stevan@iinteractive.comE<gt>
160
161 =head1 COPYRIGHT AND LICENSE
162
163 Copyright 2006-2008 by Infinity Interactive, Inc.
164
165 L<http://www.iinteractive.com>
166
167 This library is free software; you can redistribute it and/or modify
168 it under the same terms as Perl itself.
169
170 =cut