initialize the metaclass when calling ->does
[gitmo/Moose.git] / TODO
1 == Todo for 2.0400
2
3 === Revise MetaRole API to reunify class/role metaroles:
4
5   apply_metaroles(
6       for   => $meta,
7       roles => {
8           attribute => [...],
9           class     => [...],
10           role_attribute => [ ... ],
11       }
12   );
13
14 If the $meta is a class, we apply the roles to the class. If it's a role, we
15 hold onto them and apply them as part of applying the role to a class.
16
17 To make this all work nicely, we'll probably want to track the original role
18 where a method was defined, just like we do with attributes currently. We'll
19 also need to store method modifiers with their original role, which may mean
20 adding some sort of Moose::Meta::Role::MethodModifier class.
21
22 For each role-specific thing (methods, attributes, etc.) we should allow a
23 role_attribute, role_method, etc. key. The common case will be that the
24 metaroles are intended for the consuming class, but we should allow for
25 metaroles on the role's metaobjects as well.
26
27 === Deprecate old-style Moose extensions
28
29 Moose extensions that work by calling Moose->init_meta(metaclass =>
30 'Some::Custom::Metaclass', ...) during their own init_meta should be
31 deprecated, so they can be removed later (this should fix the issues with
32 init_meta generation in Moose::Exporter, see RT51561)
33
34 === Register implicitly created class/role types
35
36 When you do has foo => (isa => 'Bar'), it returns a class_type for Bar, but
37 doesn't register it. This means that later you can declare "subtype 'Bar', as
38 'Str', ..." and it'll work, and later instances of the 'Bar' type will use that
39 one. We should register the implicitly created ones so that trying to redefine
40 it after it's used throws an error.
41
42 === Attributes in roles need to be able to participate in role composition
43
44 Right now, this fails with no decent workaround:
45
46   package R1;
47   use Moose::Role;
48   has foo => (is => 'ro');
49
50   package R2;
51   use Moose::Role;
52   with 'R1';
53   requires 'foo';
54
55   package C;
56   use Moose;
57   with 'R2';
58
59 Role attributes really need to be able to participate in role-role combination.
60 This should also fix "with 'Role1', 'Role2'" being broken when Role1 implements
61 a method as an accessor and Role2 requires that method, but at least in that
62 case you can split it into two 'with' statements with minimal loss of
63 functionality.
64
65 === Method modifiers in roles should silently add 'requires' for them
66
67 This shouldn't be a functionality change, just a better error message (and
68 better introspectability). This shouldn't happen if the role already contains a
69 method by that name, so it'll depend on the previous fix going in (so "has foo
70 => (is => 'ro'); around foo => sub { }" doesn't produce a 'requires' entry).
71
72 === Add overloading support
73
74 or at least, don't break existing overloading support
75
76 This shouldn't treat the overloading stuff as actual methods, since that's just
77 an implementation detail, but we should provide an API for add_overload,
78 get_overload, get_overload_list, etc. In particular, this would allow
79 namespace::autoclean to not break things.
80
81 Also, MooseX::Role::WithOverloading should probably be cored.
82
83
84 == Todo for later
85
86 === Actual API for metaclass extensions
87
88 Right now, the only way to bundle multiple metaclass traits is via
89 Moose::Exporter. This is unhelpful if you want to apply the extension to a
90 metaclass object rather than a class you're actually writing. We should come up
91 with an API for doing this.
92
93 === MooseX::NonMoose in core
94
95 I think all of the actual issues are solved at this point. The only issue is
96 the (necessary) implementation weirdness - it sets up multiple inheritance
97 between the non-Moose class and Moose::Object, and it installs a custom
98 constructor method at 'extends' time (although perhaps this could be solved by
99 moving some of the logic back into Moose::Object::new?). Other than that, it
100 handles everything transparently as far as I can tell.
101
102 === Fix attribute and method metaclass compatibility
103
104 So i got this wrong when rewriting it last year - right now, metaclass compat
105 checks the default attribute and method metaclasses, which is wrong. This means
106 that if a parent class does "use MooseX::FollowPBP", then attributes declared
107 in a subclass will get PBP-style accessors, which is quite surprising.
108
109 On the other hand, sometimes metaclasses might need to be able to say "I'm
110 going to assume that all of my attributes at least inherit from this custom
111 class", so we might need to split it into "default specified by the user" and
112 "default specified by the metaclass" and only do compat checking on the second?
113 I'm not actually sure this is a valid use case though.
114
115 Something that probably should be taken into account though is attributes and
116 methods that extend existing attributes or methods from a superclass should
117 inherit the metaclass of the existing one. Also not sure if this is correct,
118 but something to think about.
119
120 === Rename a bunch of the public API methods
121
122 Right now the public API is kind of a mess - we have things like get_method vs
123 find_method_by_name (you almost always want to use the latter), there being no
124 has_method equivalent that checks superclasses, get_method_list being public
125 but only returning method names, while _get_local_methods is private (returning
126 method objects), and yet neither of those looks at superclasses, and basically
127 none of this naming follows any kind of consistent pattern.
128
129 What we really need is a consistent and easy to remember API where the method
130 that people would think to use first is the method that they actually mean.
131 Something like renaming find_method_by_name to find_method, and get_method to
132 find_local_method or something along those lines.
133
134
135 == Things to contemplate
136
137 === Does applying metaroles really need to reinitialize the metaclass?
138
139 Seems like the logic that's actually necessary is already contained in
140 rebless_instance, and not reinitializing means that existing attributes and
141 methods won't be blown away when metaroles are applied.
142
143 === Do we want to core namespace::autoclean behavior somehow?
144
145 This would add Variable::Magic as a required XS dep (not a huge deal at the
146 moment, since Sub::Name is also a required XS dep, but it'd be nice for Moose
147 to be able to be pure perl again at some point in the future, and I'm not sure
148 what the relative chances of Sub::Name vs Variable::Magic making it into core
149 are). If we enabled it by default, this would also break things for people who
150 have introduced Moose into legacy-ish systems where roles are faked using
151 exporters (since those imported methods would be cleaned).
152
153 If we decide we want this, we may want to core it as an option first ("use
154 Moose -clean" or so), and move to making it the default later.
155
156 === Fix the error system
157
158 oh god it's terrible
159
160 More specifically, we really want exception objects.
161
162 === Should using -excludes with a role add 'requires' for excluded methods?
163
164 It seems to make sense, since otherwise you're violating the role's API
165 contract.
166
167
168 == Old todo (does anyone look at this?)
169
170 -------------------------------------------------------------------------------
171 BUGS
172 -------------------------------------------------------------------------------
173
174 -------------------------------------------------------------------------------
175 FEATURES
176 -------------------------------------------------------------------------------
177
178 - DDuncan's Str types
179
180 subtype 'Str'
181     => as 'Value'
182     => where { Encode::is_utf8( $_[0] ) or $_[0] !~ m/[^0x00-0x7F]/x }
183     => optimize_as { defined($_[0]) && !ref($_[0]) };
184
185 subtype 'Blob'
186     => as 'Value'
187     => where { !Encode::is_utf8( $_[0] ) }
188     => optimize_as { defined($_[0]) && !ref($_[0]) };
189
190 - type unions
191
192 Add support for doing it with Classes which do not have
193 a type constraint yet created
194
195 - type intersections
196
197 Mostly just for Roles
198
199 - inherited slot specs
200
201 'does' can be added to,.. but not changed
202 (need type unions for this)
203
204 - proxy attributes
205
206 a proxied attribute is an attribute
207 which looks like an attribute,
208 talks like an attribute, smells
209 like an attribute,.. but if you
210 look behind the curtain,.. its
211 over there.. in that other object
212
213 (... probably be a custom metaclass)
214
215 - local coerce
216
217 [13:16]         mst     stevan: slight problem with coerce
218 [13:16]         mst     I only get to declare it once
219 [13:17]         mst     so if I'm trying to declare it cast-style per-source-class rather than per-target-class
220 [13:17]         mst     I am extremely screwed
221 [13:17]         stevan  yes
222 [13:17]         stevan  they are not class specific
223 [13:18]         stevan  they are attached to the type constraint itself
224 [13:18]         *       stevan ponders anon-coercion-metaobjects
225 [13:18]         mst     yes, that's fine
226 [13:19]         mst     but when I declare a class
227 [13:19]         mst     I want to be able to say "this class coerces to X type via <this>"
228 [13:19]         stevan  yeah something like that
229 [13:19]         stevan  oh,.. hmm
230 [13:20]         stevan  sort of like inflate/deflate?
231 [13:20]         stevan  around the accessors?
232 [13:25]         *       bluefeet has quit (Remote host closed the connection)
233 [13:27]         mst     no
234 [13:27]         mst     nothing like that
235 [13:27]         mst     like a cast
236 [13:31]         mst     stevan: $obj->foo($bar); where 'foo' expects a 'Foo' object
237 [13:31]         mst     stevan: is effectively <Foo>$bar, right?
238 [13:32]         mst     stevan: I want to be able to say in package Bar
239 [13:32]         mst     stevan: coerce_to 'Foo' via { ... };
240 [13:32]         mst     etc.
241 [13:53]         stevan  hmm
242
243 -----------------------------------------------------------
244 -- Type Constraints refactor
245 -----------------------------------------------------------
246
247 - add support for locally scoped TC
248
249 This would borrow from MooseX::TypeLibrary to prefix the TC with the name
250 of the package. It would then be accesible from the outside as the fully
251 scoped name, but the local attributes would use it first. (this would need support
252 in the registry for this).
253
254 - look into sugar extensions
255
256 Use roles as sugar layer function providers (ala MooseX::AttributeHelpers). This
257 would allow custom metaclasses to provide roles to extend the sugar syntax with.
258
259 (NOTE: Talk to phaylon a bit more on this)
260
261 - allow a switch of some kind to optionally turn TC checking off at runtime
262
263 The type checks can get expensive and some people have suggested that allowing
264 the checks to be turned off would be helpful for deploying into performance
265 intensive systems. Perhaps this can actually be done as an option to make_immutable?
266
267 - misc. minor bits
268
269 * make the errors for TCs use ->message
270 * look into localizing the messages too
271 * make ANON TCs be lazy, so they can possibly be subsituted for the real thing later
272 * make ANON TCs more introspectable
273 * add this ...
274
275 #
276 #   Type Definition
277 #
278 subtype 'Username',
279    from 'Str',
280   where {     (/[a-z][a-z0-9]+/i or fail('Invalid character(s)'))
281           and (length($_) >= 5   or fail('Too short (less than 5 chars)'))
282         }
283 on_fail { MyException->throw(value => $_[0], message => $_[1]) };
284
285 # fail() will just return false unless the call is made via
286 $tc->check_or_fail($value);
287
288 * and then something like this:
289
290 subtype Foo => as Bar => where { ... } => scoped => -global;
291 subtype Foo => as Bar => where { ... } => scoped => -local;
292
293 # or
294
295 subtype Foo => as Bar => where { ... } => in __PACKAGE__ ;
296
297 # or (not sure if it would be possible)
298
299 my $Foo = subtype Bar => where { ... };
300
301 # ----------
302
303 [17:10]  <autarch> stevan: it should do it if I pass coerce => 1 as part of the attribute definition
304 [17:12]  <stevan> autarch: what I am not 100% sure of is how to tell it to deep coerce and when to not
305 [17:13]  <stevan> cause a basic coerce is from A to B
306 [17:13]  <autarch> hmm
307 [17:13]  <stevan> which is valid for collection types too
308 [17:13]  <stevan> deep coercion is what you are asking for
309 [17:13]  <autarch> yeah
310 [17:13]  <stevan> so perhaps we add deep_coerce => 1
311 [17:13]  <stevan> which will do it
312 [17:13]  <autarch> that's fine for me
313 [17:13]  <stevan> k
314
315 coerce_deeply => 1 # reads better
316
317 -------------------------------------------------------------------------------
318 INTERNALS
319 -------------------------------------------------------------------------------
320
321 - rationalize all the get_X methods for classes (and roles)
322
323 We have get_attribute, get_attributes_list, get_all_attributes,
324 etc. First, we need to make the method names consistent. If something
325 returns an attribute vs a name, that needs to be clear from the method
326 name. We also need to make sure that local vs. "entire inheritance
327 chain" is clear from the name.
328
329 This is mostly a CMOP change.
330
331 - Metaclass constructors
332
333 There's a _lot_ of different conventions in here. Some things to consider:
334
335 * new vs _new
336 * allowing new( 'name', %args ) vs ( name => 'name', %args )
337 * Method->wrap vs Method->new
338
339 - Moose::Meta::TypeConstraint::Parameter{izable,ized}
340
341 The relationship between these two classes is very odd. In particular,
342 this line in Parameterized is insane:
343
344     foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
345
346 Why does it need to loop through all parameterizable types? Shouldn't
347 it know which parameterizable type it "came from"?
348
349 - Moose::Util::TypeConstraints vs Moose::Meta::Type{Coercion,Constraint}
350
351 The Util module has _way_ too much functionality. It needs to be
352 refactored so it's a thin sugar layer on top of the meta API. As it
353 stands now, it does things like parse type names (and determine if
354 they're valid), manage the registry, and much more.
355
356 - Anything with a _(meta)?class method
357
358 Every method that returns a class name needs to become a rw attribute
359 that can be set via the constructor.
360
361 - The Moose::Error stuff
362
363 This is sort of half-implemented. We still use Carp directly, and the
364 internals can't decide how to throw an error (is it
365 Moose->throw_error, __PACKAGE__->throw_error, what?).
366
367 The internals need to be made consistent before we expose this to the
368 rest of the world.
369
370 -------------------------------------------------------------------------------
371 TO PONDER
372 -------------------------------------------------------------------------------
373
374 - Moose "strict" mode
375
376 use Moose 'strict'; This would allow us to have all sort of expensive tests
377 which can be turned off in prod.
378
379 - Moose::Philosophy.pod
380
381 To explain Moose from a very high level
382
383 - moosedoc
384
385 We certainly have enough meta-information to make pretty complete POD docs.
386
387
388