NAME
Moose::Cookbook::Snack::Keywords - Restricted "keywords" in Moose
VERSION
version 1.9901
DESCRIPTION
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.
The 'meta' keyword
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.
Moose Keywords
If you are using Moose or Moose::Role its best to avoid these keywords:
Moose::Util::TypeConstraints Keywords
If you are using Moose::Util::TypeConstraints its best to avoid these keywords
- type
- subtype
- class_type
- role_type
- maybe_type
- as
- where
- message
- optimize_as
- coerce
- from
- via
- enum
- find_type_constraint
- register_type_constraint
Avoiding collisions
Turning off Moose
To remove the sugar functions Moose exports just add no Moose
at the bottom of your code:
This will unexport the sugar functions that Moose originally exported. The same will also work for Moose::Role and Moose::Util::TypeConstraints.
Sub::Exporter features
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:
See the Sub::Exporter docs for more information.
namespace::clean
You can also use namespace::clean to clean up your namespace, but you must be careful not to remove meta
when doing so:
SEE ALSO
AUTHOR
Stevan Little <stevan@iinteractive.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Infinity Interactive, Inc..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.