1# PODNAME: Moose::Cookbook::Snack::Keywords 2# ABSTRACT: Restricted "keywords" in Moose 3 4__END__ 5 6=pod 7 8=encoding UTF-8 9 10=head1 NAME 11 12Moose::Cookbook::Snack::Keywords - Restricted "keywords" in Moose 13 14=head1 VERSION 15 16version 2.2201 17 18=head1 DESCRIPTION 19 20Moose exports a number of sugar functions in order to emulate Perl 21built-in keywords. These can cause clashes with other user-defined 22functions. This document provides a list of those keywords for easy 23reference. 24 25=head2 The 'meta' keyword 26 27C<S<use Moose>> adds a method called C<meta> to your class. If this 28conflicts with a method or function you are using, you can rename it, 29or prevent it from being installed entirely. To do this, pass the 30C<-meta_name> option when you C<S<use Moose>>. For instance: 31 32 # install it under a different name 33 use Moose -meta_name => 'moose_meta'; 34 35 # don't install it at all 36 use Moose -meta_name => undef; 37 38=head2 Moose Keywords 39 40If you are using L<Moose> or L<Moose::Role> it is best to avoid these 41keywords: 42 43=over 4 44 45=item extends 46 47=item with 48 49=item has 50 51=item before 52 53=item after 54 55=item around 56 57=item super 58 59=item override 60 61=item inner 62 63=item augment 64 65=item confess 66 67=item blessed 68 69=item meta 70 71=back 72 73=head2 Moose::Util::TypeConstraints Keywords 74 75If you are using L<Moose::Util::TypeConstraints> it is best to avoid 76these keywords: 77 78=over 4 79 80=item type 81 82=item subtype 83 84=item class_type 85 86=item role_type 87 88=item maybe_type 89 90=item duck_type 91 92=item as 93 94=item where 95 96=item message 97 98=item inline_as 99 100=item coerce 101 102=item from 103 104=item via 105 106=item enum 107 108=item find_type_constraint 109 110=item register_type_constraint 111 112=back 113 114=head2 Avoiding collisions 115 116=head3 Turning off Moose 117 118To remove the sugar functions L<Moose> exports, just add C<S<no Moose>> 119at the bottom of your code: 120 121 package Thing; 122 use Moose; 123 124 # code here 125 126 no Moose; 127 128This will unexport the sugar functions that L<Moose> originally 129exported. The same will also work for L<Moose::Role> and 130L<Moose::Util::TypeConstraints>. 131 132=head3 Sub::Exporter features 133 134L<Moose>, L<Moose::Role> and L<Moose::Util::TypeConstraints> all use 135L<Sub::Exporter> to handle all their exporting needs. This means that 136all the features that L<Sub::Exporter> provides are also available to 137them. 138 139For instance, with L<Sub::Exporter> you can rename keywords, like so: 140 141 package LOL::Cat; 142 use Moose 'has' => { -as => 'i_can_haz' }; 143 144 i_can_haz 'cheeseburger' => ( 145 is => 'rw', 146 trigger => sub { print "NOM NOM" } 147 ); 148 149 LOL::Cat->new->cheeseburger('KTHNXBYE'); 150 151See the L<Sub::Exporter> docs for more information. 152 153=head3 namespace::autoclean and namespace::clean 154 155You can also use L<namespace::autoclean> to clean up your namespace. 156This will remove all imported functions from your namespace. Note 157that if you are importing functions that are intended to be used as 158methods (this includes L<overload>, due to internal implementation 159details), it will remove these as well. 160 161Another option is to use L<namespace::clean> directly, but 162you must be careful not to remove C<meta> when doing so: 163 164 package Foo; 165 use Moose; 166 use namespace::clean -except => 'meta'; 167 # ... 168 169=head1 SEE ALSO 170 171=over 4 172 173=item L<Moose> 174 175=item L<Moose::Role> 176 177=item L<Moose::Util::TypeConstraints> 178 179=item L<Sub::Exporter> 180 181=item L<namespace::autoclean> 182 183=item L<namespace::clean> 184 185=back 186 187=head1 AUTHORS 188 189=over 4 190 191=item * 192 193Stevan Little <stevan@cpan.org> 194 195=item * 196 197Dave Rolsky <autarch@urth.org> 198 199=item * 200 201Jesse Luehrs <doy@cpan.org> 202 203=item * 204 205Shawn M Moore <sartak@cpan.org> 206 207=item * 208 209יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org> 210 211=item * 212 213Karen Etheridge <ether@cpan.org> 214 215=item * 216 217Florian Ragwitz <rafl@debian.org> 218 219=item * 220 221Hans Dieter Pearcey <hdp@cpan.org> 222 223=item * 224 225Chris Prather <chris@prather.org> 226 227=item * 228 229Matt S Trout <mstrout@cpan.org> 230 231=back 232 233=head1 COPYRIGHT AND LICENSE 234 235This software is copyright (c) 2006 by Infinity Interactive, Inc. 236 237This is free software; you can redistribute it and/or modify it under 238the same terms as the Perl 5 programming language system itself. 239 240=cut 241