merge trunk to pluggable errors
[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 confess 
47
48 =item blessed 
49
50 =back
51
52 =head2 Moose::Util::TypeConstraints Keywords 
53
54 If you are using L<Moose::Util::TypeConstraints> its best to avoid 
55 these keywords 
56
57 =over 4
58
59 =item type 
60
61 =item subtype 
62
63 =item class_type 
64
65 =item role_type 
66
67 =item as 
68
69 =item where 
70
71 =item message 
72
73 =item optimize_as
74
75 =item coerce 
76
77 =item from 
78
79 =item via
80
81 =item enum
82
83 =item find_type_constraint
84
85 =item register_type_constraint
86
87 =back
88
89 =head2 Avoiding collisions
90
91 =head3 Turning off Moose
92
93 To remove the keywords L<Moose> exports just add C<no Moose> at the bottom of 
94 your code, like so:
95
96   package Thing;
97   use Moose;
98
99   # code here
100
101   no Moose;
102
103 This will un-export the keywords that L<Moose> originally exported. The same 
104 will also work for L<Moose::Role> and L<Moose::Util::TypeConstraints>. It is 
105 general L<Moose> policy that this feature is used.
106
107 =head3  Sub::Exporter
108
109 L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use 
110 L<Sub::Exporter> to handle all their exporting needs. This means that all the 
111 features that L<Sub::Exporter> provides are also available to them. 
112
113 For instance, with L<Sub::Exporter> you can rename keywords, like so:
114
115   package LOL::Cat;
116   use Moose 'has' => { -as => 'i_can_haz' };
117   
118   i_can_haz 'cheeseburger' => (
119      is      => 'rw',
120      trigger => sub { print "NOM NOM" }
121   );
122   
123   LOL::Cat->new->cheeseburger('KTHNXBYE');
124
125 See the L<Sub::Exporter> docs for more information.
126
127 =head3 namespace::clean
128
129 You can also use L<namespace::clean> to clean up your namespace, but you must 
130 be careful not to remove C<meta> with this. Here is an example of that usage:
131
132   package Foo;
133   use Moose;
134   use namespace::clean -except => 'meta';
135   # ...
136
137 =head1 SEE ALSO
138
139 =over 4
140
141 =item L<Moose>
142
143 =item L<Moose::Role>
144
145 =item L<Moose::Utils::TypeConstraints>
146
147 =item L<Sub::Exporter>
148
149 =item L<namespace::clean>
150
151 =back
152
153 =head1 AUTHOR
154
155 John Goulah C<E<lt>jgoulah@cpan.org<gt>>
156
157 Stevan Little E<lt>stevan@iinteractive.comE<gt>
158
159 =head1 COPYRIGHT AND LICENSE
160
161 Copyright 2006-2008 by Infinity Interactive, Inc.
162
163 L<http://www.iinteractive.com>
164
165 This library is free software; you can redistribute it and/or modify
166 it under the same terms as Perl itself.
167
168 =cut