Moose::Cookbook::Snack::Keywords - Restricted keywords in Moose
There are several keywords exported by Moose that can cause clashes against other user-defined barewords. The following document provides a list of those keywords in a single place for easy reference.
While most of the reserved keywords collisions can be avoided, however meta is the only one you can not override. Do not attempt to override meta, it will break the Moose internals.
If you are using Moose or Moose::Role its best to avoid these keywords:
If you are using Moose::Util::TypeConstraints its best to avoid these keywords
To remove the keywords Moose exports just add no Moose at the bottom of your code, like so:
no Moose
package Thing; use Moose; # code here no Moose;
This will un-export the keywords that Moose originally exported. The same will also work for Moose::Role and Moose::Util::TypeConstraints. It is general Moose policy that this feature is used.
Moose, Moose::Role and Moose::Util::TypeConstraints all use Sub::Exporter to handle all their exporting needs. This means that all the features that Sub::Exporter provides are also available to them.
For instance, with Sub::Exporter you can rename keywords, like so:
package LOL::Cat; use Moose 'has' => { -as => 'i_can_haz' }; i_can_haz 'cheeseburger' => ( is => 'rw', trigger => sub { print "NOM NOM" } ); LOL::Cat->new->cheeseburger('KTHNXBYE');
See the Sub::Exporter docs for more information.
You can also use namespace::clean to clean up your namespace, but you must be careful not to remove meta with this. Here is an example of that usage:
meta
package Foo; use Moose; use namespace::clean -except => 'meta'; # ...
John Goulah <jgoulah@cpan.org<gt>
<jgoulah@cpan.org<gt
Stevan Little <stevan@iinteractive.com>
Copyright 2006-2008 by Infinity Interactive, Inc.
http://www.iinteractive.com
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Moose, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Moose
CPAN shell
perl -MCPAN -e shell install Moose
For more information on module installation, please visit the detailed CPAN module installation guide.