Moose::Cookbook::Snack::Keywords - Restricted "keywords" in Moose
Moose exports a number of sugar functions in order to emulate Perl built-in keywords. These can cause clashes with other user-defined functions. This document provides a list of those keywords for easy reference.
While most collisions can be avoided, you cannot avoid importing a meta method when you use Moose. If you try to override or change what meta does, you could end up breaking Moose internals.
meta
use Moose
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 sugar functions Moose exports just add no Moose at the bottom of your code:
no Moose
package Thing; use Moose; # code here no Moose;
This will unexport the sugar functions that Moose originally exported. The same will also work for Moose::Role and Moose::Util::TypeConstraints.
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 when doing so:
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-2009 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.