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

VERSION

9       version 2.2013
10

DESCRIPTION

12       Moose exports a number of sugar functions in order to emulate Perl
13       built-in keywords. These can cause clashes with other user-defined
14       functions. This document provides a list of those keywords for easy
15       reference.
16
17   The 'meta' keyword
18       "use Moose" adds a method called "meta" to your class. If this
19       conflicts with a method or function you are using, you can rename it,
20       or prevent it from being installed entirely. To do this, pass the
21       "-meta_name" option when you "use Moose". For instance:
22
23         # install it under a different name
24         use Moose -meta_name => 'moose_meta';
25
26         # don't install it at all
27         use Moose -meta_name => undef;
28
29   Moose Keywords
30       If you are using Moose or Moose::Role it is best to avoid these
31       keywords:
32
33       extends
34       with
35       has
36       before
37       after
38       around
39       super
40       override
41       inner
42       augment
43       confess
44       blessed
45       meta
46
47   Moose::Util::TypeConstraints Keywords
48       If you are using Moose::Util::TypeConstraints it is best to avoid these
49       keywords:
50
51       type
52       subtype
53       class_type
54       role_type
55       maybe_type
56       duck_type
57       as
58       where
59       message
60       inline_as
61       coerce
62       from
63       via
64       enum
65       find_type_constraint
66       register_type_constraint
67
68   Avoiding collisions
69       Turning off Moose
70
71       To remove the sugar functions Moose exports, just add "no Moose" at the
72       bottom of your code:
73
74         package Thing;
75         use Moose;
76
77         # code here
78
79         no Moose;
80
81       This will unexport the sugar functions that Moose originally exported.
82       The same will also work for Moose::Role and
83       Moose::Util::TypeConstraints.
84
85       Sub::Exporter features
86
87       Moose, Moose::Role and Moose::Util::TypeConstraints all use
88       Sub::Exporter to handle all their exporting needs. This means that all
89       the features that Sub::Exporter provides are also available to them.
90
91       For instance, with Sub::Exporter you can rename keywords, like so:
92
93         package LOL::Cat;
94         use Moose 'has' => { -as => 'i_can_haz' };
95
96         i_can_haz 'cheeseburger' => (
97             is      => 'rw',
98             trigger => sub { print "NOM NOM" }
99         );
100
101         LOL::Cat->new->cheeseburger('KTHNXBYE');
102
103       See the Sub::Exporter docs for more information.
104
105       namespace::autoclean and namespace::clean
106
107       You can also use namespace::autoclean to clean up your namespace.  This
108       will remove all imported functions from your namespace. Note that if
109       you are importing functions that are intended to be used as methods
110       (this includes overload, due to internal implementation details), it
111       will remove these as well.
112
113       Another option is to use namespace::clean directly, but you must be
114       careful not to remove "meta" when doing so:
115
116         package Foo;
117         use Moose;
118         use namespace::clean -except => 'meta';
119         # ...
120

SEE ALSO

122       Moose
123       Moose::Role
124       Moose::Util::TypeConstraints
125       Sub::Exporter
126       namespace::autoclean
127       namespace::clean
128

AUTHORS

130       ·   Stevan Little <stevan.little@iinteractive.com>
131
132       ·   Dave Rolsky <autarch@urth.org>
133
134       ·   Jesse Luehrs <doy@tozt.net>
135
136       ·   Shawn M Moore <code@sartak.org>
137
138       ·   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
139
140       ·   Karen Etheridge <ether@cpan.org>
141
142       ·   Florian Ragwitz <rafl@debian.org>
143
144       ·   Hans Dieter Pearcey <hdp@weftsoar.net>
145
146       ·   Chris Prather <chris@prather.org>
147
148       ·   Matt S Trout <mst@shadowcat.co.uk>
149
151       This software is copyright (c) 2006 by Infinity Interactive, Inc.
152
153       This is free software; you can redistribute it and/or modify it under
154       the same terms as the Perl 5 programming language system itself.
155
156
157
158perl v5.32.0                      2020-07-28Moose::Cookbook::Snack::Keywords(3)
Impressum