1Moose::Cookbook::Snack:U:sKeerywCoorndtsr(i3b)uted PerlMDooocsuem:e:nCtoaotkiboonok::Snack::Keywords(3)
2
3
4

NAME

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

DESCRIPTION

9       Moose exports a number of sugar functions in order to emulate Perl
10       built-in keywords. These can cause clashes with other user-defined
11       functions. This document provides a list of those keywords for easy
12       reference.
13
14   The 'meta' keyword
15       While most collisions can be avoided, you cannot avoid importing a
16       "meta" method when you "use Moose". If you try to override or change
17       what "meta" does, you could end up breaking Moose internals.
18
19   Moose Keywords
20       If you are using Moose or Moose::Role its best to avoid these keywords:
21
22       extends
23       with
24       has
25       before
26       after
27       around
28       super
29       override
30       inner
31       augment
32       confess
33       blessed
34
35   Moose::Util::TypeConstraints Keywords
36       If you are using Moose::Util::TypeConstraints its best to avoid these
37       keywords
38
39       type
40       subtype
41       class_type
42       role_type
43       maybe_type
44       as
45       where
46       message
47       optimize_as
48       coerce
49       from
50       via
51       enum
52       find_type_constraint
53       register_type_constraint
54
55   Avoiding collisions
56       Turning off Moose
57
58       To remove the sugar functions Moose exports just add "no Moose" at the
59       bottom of your code:
60
61         package Thing;
62         use Moose;
63
64         # code here
65
66         no Moose;
67
68       This will unexport the sugar functions that Moose originally exported.
69       The same will also work for Moose::Role and
70       Moose::Util::TypeConstraints.
71
72       Sub::Exporter features
73
74       Moose, Moose::Role and Moose::Util::TypeConstraints all use
75       Sub::Exporter to handle all their exporting needs. This means that all
76       the features that Sub::Exporter provides are also available to them.
77
78       For instance, with Sub::Exporter you can rename keywords, like so:
79
80         package LOL::Cat;
81         use Moose 'has' => { -as => 'i_can_haz' };
82
83         i_can_haz 'cheeseburger' => (
84             is      => 'rw',
85             trigger => sub { print "NOM NOM" }
86         );
87
88         LOL::Cat->new->cheeseburger('KTHNXBYE');
89
90       See the Sub::Exporter docs for more information.
91
92       namespace::clean
93
94       You can also use namespace::clean to clean up your namespace, but you
95       must be careful not to remove "meta" when doing so:
96
97         package Foo;
98         use Moose;
99         use namespace::clean -except => 'meta';
100         # ...
101

SEE ALSO

103       Moose
104       Moose::Role
105       Moose::Utils::TypeConstraints
106       Sub::Exporter
107       namespace::clean
108

AUTHOR

110       John Goulah "<jgoulah@cpan.org<gt">
111
112       Stevan Little <stevan@iinteractive.com>
113
115       Copyright 2006-2010 by Infinity Interactive, Inc.
116
117       <http://www.iinteractive.com>
118
119       This library is free software; you can redistribute it and/or modify it
120       under the same terms as Perl itself.
121
122
123
124perl v5.12.2                      2010-08-21Moose::Cookbook::Snack::Keywords(3)
Impressum