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       ·   overload, B::Hooks::EndOfScope, namespace::autoclean, Class::MOP,
142
143       ·   Moose.
144
145       ·   MooseX::Role::WithOverloading does allow for overload application
146           from
147
148       ·   roles, but it does this by copying the overload symbols from the
149           (not
150
151       ·   namespace::autoclean'ed role) the symbols handing overloads during
152           class
153
154       ·   composition; we work by marking the overloads as methods and
155           letting
156
157       ·   CMOP/Moose handle them.
158

SOURCE

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

BUGS

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

AUTHOR

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

POD ERRORS

182       Hey! The above document had some coding errors, which are explained
183       below:
184
185       Around line 320:
186           alternative text 'CMOP/Moose handle them.' contains non-escaped |
187           or /
188
189
190
191perl v5.28.1                      2012-05-31          MooseX::MarkAsMethods(3)
Impressum