1MooseX::MarkAsMethods(3U)ser Contributed Perl DocumentatiMoonoseX::MarkAsMethods(3)
2
3
4

NAME

6       MooseX::MarkAsMethods - Mark overload code symbols as methods
7

VERSION

9       This document describes version 0.15 of MooseX::MarkAsMethods -
10       released May 30, 2012 as part of MooseX-MarkAsMethods.
11

SYNOPSIS

13           package Foo;
14           use Moose;
15
16           # mark overloads as methods and wipe other non-methods
17           use MooseX::MarkAsMethods autoclean => 1;
18
19           # define overloads, etc as normal
20           use overload '""' => sub { shift->stringify };
21
22           package Baz;
23           use Moose::Role;
24           use MooseX::MarkAsMethods autoclean => 1;
25
26           # overloads defined in a role will "just work" when the role is
27           # composed into a class; they MUST use the anon-sub style invocation
28           use overload '""' => sub { shift->stringify };
29
30           # additional methods generated outside Class::MOP/Moose can be marked, too
31           use constant foo => 'bar';
32           __PACKAGE__->meta->mark_as_method('foo');
33
34           package Bar;
35           use Moose;
36
37           # order is important!
38           use namespace::autoclean;
39           use MooseX::MarkAsMethods;
40
41           # ...
42

DESCRIPTION

44       MooseX::MarkAsMethods allows one to easily mark certain functions as
45       Moose methods.  This will allow other packages such as
46       namespace::autoclean to operate without blowing away your overloads.
47       After using MooseX::MarkAsMethods your overloads will be recognized by
48       Class::MOP as being methods, and class extension as well as composition
49       from roles with overloads will "just work".
50
51       By default we check for overloads, and mark those functions as methods.
52
53       If "autoclean => 1" is passed to import on using this module, we
54       will invoke namespace::autoclean to clear out non-methods.
55

TRAITS APPLIED

57       Using this package causes a trait to be applied to your metaclass (for
58       both roles and classes), that provides a mark_as_method() method.  You
59       can use this to mark newly generated methods at runtime (e.g. during
60       class composition) that some other package has created for you.
61
62       mark_as_method() is invoked with one or more names to mark as a method.
63       We die on any error (e.g. name not in symbol table, already a method,
64       etc).  e.g.
65
66           __PACKAGE__->meta->mark_as_method('newly_generated');
67
68       e.g. say you have some sugar from another package that creates
69       accessors of some sort; you could mark them as methods via a method
70       modifier:
71
72           # called as __PACKAGE__->foo_generator('name', ...)
73           after 'foo_generator' => sub {
74
75               shift->meta->mark_as_method(shift);
76           };
77

IMPLICATIONS FOR ROLES

79       Using MooseX::MarkAsMethods in a role will cause Moose to track and
80       treat your overloads like any other method defined in the role, and
81       things will "just work".  That's it.
82
83       Except...  note that due to the way overloads, roles, and Moose work,
84       you'll need to use the coderef or anonymous subroutine approach to
85       overload declaration, or things will not work as you expect.  Remember,
86       we're talking about _methods_ here, so we need to make it easy for
87       overload to find the right method.  The easiest (and supported) way to
88       do this is to create an anonymous sub to wrap the overload method.
89
90       That is, this will work:
91
92           # note method resolution, things will "just work"
93           use overload '""' => sub { shift->stringify };
94
95       ...and this will not:
96
97           use overload '""' => 'stringify';
98
99       ...and will result in an error message like:
100
101           # wah-wah
102           Can't resolve method "???" overloading """" in package "overload"
103

CAVEATS

105   Roles
106       See the "IMPLICATIONS FOR ROLES" section, above.
107
108   meta->mark_as_method()
109       You almost certainly don't need or want to do this.  CMOP/Moose are
110       fairly good about determining what is and what isn't a method, but not
111       perfect.  Before using this method, you should pause and think about
112       why you need to.
113
114   namespace::autoclean
115       As currently implemented, we run our "method maker" at the end of the
116       calling package's compile scope (B::Hooks::EndOfScope).  As
117       namespace::autoclean does the same thing, it's important that if
118       namespace::autoclean is used that it be used BEFORE
119       MooseX::MarkAsMethods, so that its end_of_scope block is run after
120       ours.
121
122       e.g.
123
124           # yes!
125           use namespace::autoclean;
126           use MooseX::MarkAsMethods;
127
128           # no -- overloads will be removed
129           use MooseX::MarkAsMethods;
130           use namespace::autoclean;
131
132       The easiest way to invoke this module and clean out non-methods without
133       having to worry about ordering is:
134
135           use MooseX::MarkAsMethods autoclean => 1;
136

SEE ALSO

138       Please see those modules/websites for more information related to this
139       module.
140
141       ·   , , , ,
142
143       ·   .
144
145       ·
146            does allow for overload application from
147
148       ·   roles, but it does this by copying the overload symbols from the
149           (not
150
151       ·   'ed role) the symbols handing overloads during class
152
153       ·   composition; we work by marking the overloads as methods and
154           letting
155
156       ·   CMOP/Moose handle them.
157

SOURCE

159       The development version is on github at
160       <http://github.com/RsrchBoy/moosex-markasmethods> and may be cloned
161       from <git://github.com/RsrchBoy/moosex-markasmethods.git>
162

BUGS

164       Please report any bugs or feature requests on the bugtracker website
165       https://github.com/RsrchBoy/moosex-markasmethods/issues
166
167       When submitting a bug or request, please include a test-file or a patch
168       to an existing test-file that illustrates the bug or desired feature.
169

AUTHOR

171       Chris Weyl <cweyl@alumni.drew.edu>
172
174       This software is Copyright (c) 2011 by Chris Weyl.
175
176       This is free software, licensed under:
177
178         The GNU Lesser General Public License, Version 2.1, February 1999
179

POD ERRORS

181       Hey! The above document had some coding errors, which are explained
182       below:
183
184       Around line 296:
185           Nested L<> are illegal.  Pretending inner one is X<...> so can
186           continue looking for other errors.
187
188           Nested L<> are illegal.  Pretending inner one is X<...> so can
189           continue looking for other errors.
190
191           Nested L<> are illegal.  Pretending inner one is X<...> so can
192           continue looking for other errors.
193
194           Nested L<> are illegal.  Pretending inner one is X<...> so can
195           continue looking for other errors.
196
197           Nested L<> are illegal.  Pretending inner one is X<...> so can
198           continue looking for other errors.
199
200           Nested L<> are illegal.  Pretending inner one is X<...> so can
201           continue looking for other errors.
202
203           Nested L<> are illegal.  Pretending inner one is X<...> so can
204           continue looking for other errors.
205
206           Nested L<> are illegal.  Pretending inner one is X<...> so can
207           continue looking for other errors.
208
209       Around line 300:
210           Nested L<> are illegal.  Pretending inner one is X<...> so can
211           continue looking for other errors.
212
213           Nested L<> are illegal.  Pretending inner one is X<...> so can
214           continue looking for other errors.
215
216       Around line 304:
217           Nested L<> are illegal.  Pretending inner one is X<...> so can
218           continue looking for other errors.
219
220           Nested L<> are illegal.  Pretending inner one is X<...> so can
221           continue looking for other errors.
222
223       Around line 312:
224           Nested L<> are illegal.  Pretending inner one is X<...> so can
225           continue looking for other errors.
226
227           Nested L<> are illegal.  Pretending inner one is X<...> so can
228           continue looking for other errors.
229
230       Around line 320:
231           alternative text 'CMOP/Moose handle them.' contains non-escaped |
232           or /
233
234
235
236perl v5.32.0                      2020-07-28          MooseX::MarkAsMethods(3)
Impressum