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



NAME

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


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 the Moose::Role manpage its best to avoid these keywords:

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

Moose::Util::TypeConstraints Keywords

If you are using the Moose::Util::TypeConstraints manpage 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:

  package Thing;
  use Moose;
  # code here
  no Moose;

This will unexport the sugar functions that Moose originally exported. The same will also work for the Moose::Role manpage and the Moose::Util::TypeConstraints manpage.

Sub::Exporter features

Moose, the Moose::Role manpage and the Moose::Util::TypeConstraints manpage all use the Sub::Exporter manpage to handle all their exporting needs. This means that all the features that the Sub::Exporter manpage provides are also available to them.

For instance, with the Sub::Exporter manpage 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 the Sub::Exporter manpage docs for more information.

namespace::clean

You can also use the namespace::clean manpage 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';
  # ...


SEE ALSO

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


AUTHOR

John Goulah <jgoulah@cpan.org<gt>

Stevan Little <stevan@iinteractive.com>


COPYRIGHT AND LICENSE

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.

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