Commit | Line | Data |
4499a7ab |
1 | =pod |
2 | |
3 | =head1 NAME |
4 | |
5 | Moose::Cookbook::Snack::Keywords - Restricted keywords in Moose |
6 | |
7 | =cut |
8 | |
9 | =head1 DESCRIPTION |
10 | |
11 | There are several keywords exported in L<Moose> that cause clashes against |
12 | any barewords such as attribute names, sub names, and globs. |
13 | |
14 | |
15 | =head2 The 'meta' keyword |
16 | |
17 | While most of the reserved keywords collisions can be avoided, however |
18 | I<meta> is the only one you B<cant> override. Do not attempt to override |
19 | I<meta>. |
20 | |
21 | =head2 Moose Keywords |
22 | |
23 | If you are using Moose its best to avoid these keywords |
24 | |
25 | =over 4 |
26 | |
27 | =item extends |
28 | |
29 | =item with |
30 | |
31 | =item has |
32 | |
33 | =item before |
34 | |
35 | =item after |
36 | |
37 | =item around |
38 | |
39 | =item super |
40 | |
41 | =item override |
42 | |
43 | =item inner |
44 | |
45 | =item augment |
46 | |
47 | =item make_immutable |
48 | |
49 | =item confess |
50 | |
51 | =item blessed |
52 | |
53 | =back |
54 | |
55 | =head2 Moose::Util::TypeConstraints Keywords |
56 | |
57 | If you are using Moose::Util::TypeConstraints its best to avoid |
58 | these keywords |
59 | |
60 | =over 4 |
61 | |
62 | =item type |
63 | |
64 | =item subtype |
65 | |
66 | =item class_type |
67 | |
68 | =item role_type |
69 | |
70 | =item as |
71 | |
72 | =item where |
73 | |
74 | =item message |
75 | |
76 | =item optimize_as |
77 | |
78 | =item coerce |
79 | |
80 | =item from |
81 | |
82 | =item via |
83 | |
84 | =item enum |
85 | |
86 | =item find_type_constraint |
87 | |
88 | =item register_type_constraint |
89 | |
90 | =back |
91 | |
92 | =head2 Avoiding collisions |
93 | |
94 | =head3 Turning off Moose |
95 | |
96 | To remove the keywords Moose exports using no Moose at the bottom of your code |
97 | |
98 | package Thing; |
99 | use Moose; |
100 | |
101 | # code here |
102 | |
103 | no Moose; |
104 | |
105 | =head3 Sub::Exporter |
106 | |
107 | The L<Sub::Exporter> module can rename keywords |
108 | |
109 | package LOL::Cat; |
110 | use Moose 'has' => { -as => 'i_can_haz' }; |
111 | |
112 | i_can_haz 'cheeseburger' => ( |
113 | is => 'rw', |
114 | trigger => sub { print "NOM NOM" } |
115 | ); |
116 | |
117 | LOL::Cat->new->cheeseburger('KTHNXBYE');; |
118 | |
119 | =head3 namespace::clean |
120 | |
121 | You can use L<namespace::clean> to clean up the namespace |
122 | |
123 | =head1 AUTHOR AND COPYRIGHT |
124 | |
125 | John Goulah C<E<lt>jgoulah@cpan.org<gt>> |
126 | |
127 | =head1 LICENSE |
128 | |
129 | This program is free software; you can redistribute it and/or modify |
130 | it under the same terms as perl itself. |
131 | |
132 | =cut |