Stevan Little > Moose-0.54 > Moose::Cookbook::Snack::Keywords

Download:
Moose-0.54.tar.gz

Annotate this POD

CPAN RT

New  13
Open  42
Stalled  7
View/Report Bugs
Source   Latest Release: Moose-2.1303-TRIAL

NAME ^

Moose::Cookbook::Snack::Keywords - Restricted keywords in Moose

DESCRIPTION ^

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.

The 'meta' keyword

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.

Moose Keywords

If you are using Moose or Moose::Role its best to avoid these keywords:

extends
with
has
before
after
around
super
override
inner
augment
make_immutable
confess
blessed

Moose::Util::TypeConstraints Keywords

If you are using Moose::Util::TypeConstraints its best to avoid these keywords

type
subtype
class_type
role_type
as
where
message
optimize_as
coerce
from
via
enum
find_type_constraint
register_type_constraint

Avoiding collisions

Turning off Moose

To remove the keywords Moose exports just add no Moose at the bottom of your code, like so:

  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.

Sub::Exporter

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.

namespace::clean

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:

  package Foo;
  use Moose;
  use namespace::clean -except => 'meta';
  # ...

SEE ALSO ^

Moose
Moose::Role
Moose::Utils::TypeConstraints
Sub::Exporter
namespace::clean

AUTHOR ^

John Goulah <jgoulah@cpan.org<gt>

Stevan Little <stevan@iinteractive.com>

COPYRIGHT AND LICENSE ^

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.

syntax highlighting: