lib/Moose/Meta/Attribute/Native/Trait.pm: factor out some of the namespace resolution...
[gitmo/Moose.git] / TODO
CommitLineData
ea8e79f1 1# vim: set ft=markdown :
2
6e6a1027 3## Uncontroversial Items
85910734 4
6e6a1027 5These items are reasonably well thought out, and can go in any major release.
6
7### RT Tickets
1b1eb1ca 8
c78a59d7 9RT#59478/RT#63000 - 0+ overload causes NV conversion on == on perls before
105.14 - this causes comparisons to fail when the number can't fit in an NV
11without precision loss. I'd like to fix this in a more general way (forcing
12anyone else who might be using == on tc objects to do weird things isn't very
13good), although it's hard to test to see what actually works.
14
6e6a1027 15### Revise MetaRole API to reunify class/role metaroles:
85910734 16
6e6a1027 17 apply_metaroles(
18 for => $meta,
19 roles => {
20 attribute => [...],
21 class => [...],
22 role_attribute => [ ... ],
23 }
24 );
85910734 25
26If the $meta is a class, we apply the roles to the class. If it's a role, we
27hold onto them and apply them as part of applying the role to a class.
28
29To make this all work nicely, we'll probably want to track the original role
30where a method was defined, just like we do with attributes currently. We'll
31also need to store method modifiers with their original role, which may mean
32adding some sort of Moose::Meta::Role::MethodModifier class.
33
34For each role-specific thing (methods, attributes, etc.) we should allow a
6e6a1027 35`role_attribute`, `role_method`, etc. key. The common case will be that the
85910734 36metaroles are intended for the consuming class, but we should allow for
37metaroles on the role's metaobjects as well.
38
6e6a1027 39### Deprecate old-style Moose extensions
ef0801e7 40
6e6a1027 41Moose extensions that work by calling `Moose->init_meta(metaclass =>
ea8e79f1 42'Some::Custom::Metaclass', ...)` during their own `init_meta` should be
ef0801e7 43deprecated, so they can be removed later (this should fix the issues with
6e6a1027 44`init_meta` generation in Moose::Exporter, see RT51561)
ef0801e7 45
6e6a1027 46This needs to wait until the previous fix gets in, since it will hopefully
ea8e79f1 47eliminate the need to write custom `init_meta` methods entirely.
d8fed7e3 48
6e6a1027 49### Attributes in roles need to be able to participate in role composition
24b9aca7 50
51Right now, this fails with no decent workaround:
52
6e6a1027 53 package R1;
54 use Moose::Role;
55 has foo => (is => 'ro');
24b9aca7 56
6e6a1027 57 package R2;
58 use Moose::Role;
59 with 'R1';
60 requires 'foo';
24b9aca7 61
6e6a1027 62 package C;
63 use Moose;
64 with 'R2';
24b9aca7 65
66Role attributes really need to be able to participate in role-role combination.
67This should also fix "with 'Role1', 'Role2'" being broken when Role1 implements
68a method as an accessor and Role2 requires that method, but at least in that
69case you can split it into two 'with' statements with minimal loss of
70functionality.
71
6e6a1027 72### Method modifiers in roles should silently add 'requires' for them
24b9aca7 73
74This shouldn't be a functionality change, just a better error message (and
75better introspectability). This shouldn't happen if the role already contains a
76method by that name, so it'll depend on the previous fix going in (so "has foo
77=> (is => 'ro'); around foo => sub { }" doesn't produce a 'requires' entry).
78
6e6a1027 79### has +foo in roles
80
81There's no actual reason for this not to work, and it gets asked often enough
82that we really should just do it at some point.
83
ea8e79f1 84### use Sub::Identify instead of doing our own thing with `get_code_info`
6e6a1027 85
86No idea why we stopped using Sub::Identify in the past, but there's no reason
ea8e79f1 87not to do this. We have a bug fix in our version (the `isGV_with_GP` thing), so
6e6a1027 88this should be submitted to Sub::Identify first.
89
90## Needs Thought
91
92These are things we think are good ideas, but they need more fleshing out.
93
94### Add overloading support
24b9aca7 95
96or at least, don't break existing overloading support
97
98This shouldn't treat the overloading stuff as actual methods, since that's just
ea8e79f1 99an implementation detail, but we should provide an API for `add_overload`,
100`get_overload`, `get_overload_list`, etc. In particular, this would allow
24b9aca7 101namespace::autoclean to not break things.
102
103Also, MooseX::Role::WithOverloading should probably be cored.
104
d8fed7e3 105This should probably also wait for the metarole unification fix, to avoid the
106::WithOverloading stuff being too insane.
107
6e6a1027 108### Actual API for metaclass extensions
24b9aca7 109
110Right now, the only way to bundle multiple metaclass traits is via
111Moose::Exporter. This is unhelpful if you want to apply the extension to a
112metaclass object rather than a class you're actually writing. We should come up
113with an API for doing this.
114
6e6a1027 115### MooseX::NonMoose in core
24b9aca7 116
117I think all of the actual issues are solved at this point. The only issue is
118the (necessary) implementation weirdness - it sets up multiple inheritance
119between the non-Moose class and Moose::Object, and it installs a custom
120constructor method at 'extends' time (although perhaps this could be solved by
121moving some of the logic back into Moose::Object::new?). Other than that, it
122handles everything transparently as far as I can tell.
123
6e6a1027 124### Fix attribute and method metaclass compatibility
24b9aca7 125
126So i got this wrong when rewriting it last year - right now, metaclass compat
127checks the default attribute and method metaclasses, which is wrong. This means
128that if a parent class does "use MooseX::FollowPBP", then attributes declared
129in a subclass will get PBP-style accessors, which is quite surprising.
130
131On the other hand, sometimes metaclasses might need to be able to say "I'm
132going to assume that all of my attributes at least inherit from this custom
133class", so we might need to split it into "default specified by the user" and
134"default specified by the metaclass" and only do compat checking on the second?
135I'm not actually sure this is a valid use case though.
136
137Something that probably should be taken into account though is attributes and
138methods that extend existing attributes or methods from a superclass should
139inherit the metaclass of the existing one. Also not sure if this is correct,
140but something to think about.
141
6e6a1027 142### Rename a bunch of the public API methods
24b9aca7 143
6e6a1027 144Right now the public API is kind of a mess - we have things like `get_method`
ea8e79f1 145vs `find_method_by_name` (you almost always want to use the latter), there
6e6a1027 146being no `has_method` equivalent that checks superclasses, `get_method_list`
147being public but only returning method names, while `_get_local_methods` is
148private (returning method objects), and yet neither of those looks at
149superclasses, and basically none of this naming follows any kind of consistent
150pattern.
24b9aca7 151
152What we really need is a consistent and easy to remember API where the method
153that people would think to use first is the method that they actually mean.
6e6a1027 154Something like renaming `find_method_by_name` to `find_method`, and `get_method` to
155`find_local_method` or something along those lines.
24b9aca7 156
6e6a1027 157### Clean up metaclass constructors
6ddfb832 158
6e6a1027 159There's a _lot_ of different conventions in here. Some things to consider:
6ddfb832 160
ea8e79f1 161* `new` vs `_new`
6e6a1027 162* allowing new( 'name', %args ) vs ( name => 'name', %args )
ea8e79f1 163* `Method->wrap` vs `Method->new`
6e6a1027 164
165### Move method modifiers out to an external module
c762df57 166
167Class::Method::Modifiers uses a different method for doing method modifiers,
168which I'm not sure why we aren't using in Moose right now. Optionally using
169Class::Method::Modifiers::Fast would be even better - it uses Data::Util to
170implement XS method modifiers, which could help things a lot.
171
6e6a1027 172### Move type constraints out to an external module
c762df57 173
174There's nothing about our type constraint system that requires being tied to
175Moose - it's conceptually an entirely separate system that Moose just happens
176to use. Splitting it out into its own thing (that Moose could extend to add
177things like role types) would make things conceptually a lot cleaner, and would
178let people interested in just the type system have that.
179
6e6a1027 180### Merge Class::MOP and Moose
c762df57 181
182This is a long term goal, but would allow for a lot of things to be cleaned up.
183There's a bunch of stuff that's duplicated, and other stuff that's not
184implemented as well as it could be (Class::MOP::Method::Wrapped should be a
185role, for instance).
186
6e6a1027 187### Fix the error system
188
189oh god it's terrible
190
191More specifically, we really want exception objects.
192
193### Moose::Util::TypeConstraints vs Moose::Meta::Type{Coercion,Constraint}
194
195The Util module has _way_ too much functionality. It needs to be
196refactored so it's a thin sugar layer on top of the meta API. As it
197stands now, it does things like parse type names (and determine if
198they're valid), manage the registry, and much more.
199
ea8e79f1 200### Anything with a \_(meta)?class method
6e6a1027 201
202Every method that returns a class name needs to become a rw attribute
203that can be set via the constructor.
204
1c76bb0e 205### Make method conflicts in role -> role application silent
206
207Right now this becomes a conflict. We should make this simply ignore the
208applied role's method (consumer wins), just like with classes.
209
210Note that this does *not* apply to role summation, where the current behavior
211(generates a conflict) is correct.
212
6e6a1027 213## Things to contemplate
24b9aca7 214
6e6a1027 215These are ideas we're not sure about. Prototypes are welcome, but we may never
216merge the feature.
24b9aca7 217
6e6a1027 218### Does applying metaroles really need to reinitialize the metaclass?
24b9aca7 219
220Seems like the logic that's actually necessary is already contained in
ea8e79f1 221`rebless_instance`, and not reinitializing means that existing attributes and
24b9aca7 222methods won't be blown away when metaroles are applied.
223
6e6a1027 224### Do we want to core namespace::autoclean behavior somehow?
24b9aca7 225
226This would add Variable::Magic as a required XS dep (not a huge deal at the
227moment, since Sub::Name is also a required XS dep, but it'd be nice for Moose
228to be able to be pure perl again at some point in the future, and I'm not sure
229what the relative chances of Sub::Name vs Variable::Magic making it into core
230are). If we enabled it by default, this would also break things for people who
231have introduced Moose into legacy-ish systems where roles are faked using
232exporters (since those imported methods would be cleaned).
233
234If we decide we want this, we may want to core it as an option first ("use
235Moose -clean" or so), and move to making it the default later.
236
6e6a1027 237### Should using -excludes with a role add 'requires' for excluded methods?
24b9aca7 238
6e6a1027 239It seems to make sense, since otherwise you're violating the role's API
240contract.
24b9aca7 241
6e6a1027 242### Moose "strict" mode
24b9aca7 243
6e6a1027 244use Moose 'strict'; This would allow us to have all sort of expensive tests
245which can be turned off in prod.
24b9aca7 246
6e6a1027 247### Moose::Philosophy.pod
248
249To explain Moose from a very high level
250
251### moosedoc
24b9aca7 252
6e6a1027 253We certainly have enough meta-information to make pretty complete POD docs.
24b9aca7 254
6e6a1027 255## TODO test summary
98fb200c 256
257Note that some of these are fairly old, and may not be things we actually want
258to do anymore.
259
6e6a1027 260### `t/basics/basic_class_setup.t`
98fb200c 261
262Imports aren't automatically cleaned. Need to think about bringing
263namespace::autoclean functionality into core.
264
6e6a1027 265### `t/bugs/create_anon_recursion.t`
98fb200c 266
267Loading Moose::Meta::Class (or probably a lot of other metaclasses) before
268loading Moose or Class::MOP causes issues (the bootstrapping gets confused).
269
6e6a1027 270### `t/bugs/handles_foreign_class_bug.t`
98fb200c 271
272There should be a warning when delegated methods override 'new' (and possibly
273others?).
274
6e6a1027 275### `t/bugs/role_caller.t`
98fb200c 276
277Role methods should be cloned into classes on composition so that using
278caller(0) in a role method uses the class's package, not the role's.
279
6e6a1027 280### `t/cmop/metaclass_incompatibility.t`
98fb200c 281
282If a child class is created before a parent class, metaclass compatibility
283checks won't run on the child when the parent is created, and so the child
284could end up with an incompatible metaclass.
285
6e6a1027 286### `t/cmop/modify_parent_method.t`
98fb200c 287
288Modifying parent class methods after a child class has already wrapped them
289with a method modifier will cause the child class method to retain the original
290method that it wrapped, not the new one it was replaced with.
291
6e6a1027 292### `t/immutable/inline_close_over.t`
98fb200c 293
294Initializers and custom error classes still close over metaobjects.
295Initializers do it because the initializer has to be passed in the attribute
296metaobject as a parameter, and custom error classes can't be automatically
297inlined.
298
6e6a1027 299### `t/metaclasses/moose_exporter_trait_aliases.t`
98fb200c 300
301Renamed imports aren't cleaned on unimport. For instance:
302
6e6a1027 303 package Foo;
304 use Moose has => { -as => 'my_has' };
305 no Moose;
306 # Foo still contains my_has
98fb200c 307
6e6a1027 308### `t/metaclasses/reinitialize.t`
98fb200c 309
310Special method types can't have method metaroles applied. Applying a method
311metarole to a class doesn't apply that role to things like constructors,
312accessors, etc.
313
6e6a1027 314### `t/roles/compose_overloading.t`
98fb200c 315
316Overload methods aren't composed during role composition (this is detailed
317above - Add overloading support).
318
6e6a1027 319### `t/roles/method_modifiers.t`
98fb200c 320
321Method modifiers in roles don't support the regex form of method selection.
322
6e6a1027 323### `t/roles/role_compose_requires.t`
98fb200c 324
325Accessors for attributes defined in roles don't satisfy role method
326requirements (this is detailed above - Attributes in roles need to be able to
327participate in role composition).
328
6e6a1027 329### `t/todo_tests/exception_reflects_failed_constraint.t`
98fb200c 330
331Type constraint failures should indicate which ancestor constraint failed -
332subtype 'Foo', as 'Str', where { length < 5 } should mention Str when passed an
333arrayref, but not when passed the string "ArrayRef".
334
6e6a1027 335### `t/todo_tests/moose_and_threads.t`
98fb200c 336
337On 5.8, the type constraint name parser isn't thread safe.
338
6e6a1027 339### `t/todo_tests/replacing_super_methods.t`
98fb200c 340
341Modifying parent class methods after a child class has already wrapped them
342with a override will cause 'super' in the child class to call the original
343parent class method, not the one it was overridden with.
344
6e6a1027 345### `t/todo_tests/required_role_accessors.t`
98fb200c 346
347Role attribute accessors don't satisfy requires from roles they consume.
348
6e6a1027 349### `t/todo_tests/role_insertion_order.t`
98fb200c 350
ea8e79f1 351Roles don't preserve attribute `insertion_order`.
98fb200c 352
6e6a1027 353### `t/todo_tests/various_role_features.t`
98fb200c 354
355* Role attribute accessors don't satisfy requires from roles they consume.
356* Role combination should produce a conflict when one role has an actual method
357 and the other role has an accessor.
358* Role attribute accessors should not override methods in the class the role is
359 applied to.
360* Role attribute accessors should be delegated when a class does
361 handles => 'Role'.
362* Delegating to a role doesn't make $class->does('Role') true.
363* Method modifier in a role doesn't create a method requirement.
ea8e79f1 364* `Role->meta->has_method('attr_accessor')` is false.
98fb200c 365
6e6a1027 366### `t/type_constraints/type_names.t`
98fb200c 367
368Type constraint object constructors don't validate the type name provided.
369
6bd51c54 370### MooseX::Aliases in core
371
372Is there any reason why this would be bad? It would certainly make the
373implementation a little faster (it can be inlined better).
374
375### MooseX::MethodAttributes in core
376
377discuss
378
6e6a1027 379----
98fb200c 380
6e6a1027 381## Old todo
43d599e5 382
6e6a1027 383Old todo stuff which may be totally out of date.
8b59f8d6 384
6e6a1027 385### DDuncan's Str types
d4967760 386
6e6a1027 387 subtype 'Str'
388 => as 'Value'
389 => where { Encode::is_utf8( $_[0] ) or $_[0] !~ m/[^0x00-0x7F]/x }
390 => optimize_as { defined($_[0]) && !ref($_[0]) };
d4967760 391
6e6a1027 392 subtype 'Blob'
393 => as 'Value'
394 => where { !Encode::is_utf8( $_[0] ) }
395 => optimize_as { defined($_[0]) && !ref($_[0]) };
d4967760 396
6e6a1027 397### type unions
8b59f8d6 398
6e6a1027 399Add support for doing it with Classes which do not have a type constraint yet
400created
8b59f8d6 401
6e6a1027 402### type intersections
8b59f8d6 403
404Mostly just for Roles
6bd51c54 405KENTNL is working on this
8b59f8d6 406
6e6a1027 407### inherited slot specs
8b59f8d6 408
6e6a1027 409'does' can be added to,.. but not changed (need type unions for this)
8b59f8d6 410
6e6a1027 411### proxy attributes
8b59f8d6 412
6e6a1027 413a proxied attribute is an attribute which looks like an attribute, talks like
414an attribute, smells like an attribute,.. but if you look behind the
415curtain,.. its over there.. in that other object
db1ab48d 416
417(... probably be a custom metaclass)
8b59f8d6 418
6e6a1027 419### local coerce
420
421 [13:16] mst stevan: slight problem with coerce
422 [13:16] mst I only get to declare it once
423 [13:17] mst so if I'm trying to declare it cast-style per-source-class rather than per-target-class
424 [13:17] mst I am extremely screwed
425 [13:17] stevan yes
426 [13:17] stevan they are not class specific
427 [13:18] stevan they are attached to the type constraint itself
428 [13:18] * stevan ponders anon-coercion-metaobjects
429 [13:18] mst yes, that's fine
430 [13:19] mst but when I declare a class
431 [13:19] mst I want to be able to say "this class coerces to X type via <this>"
432 [13:19] stevan yeah something like that
433 [13:19] stevan oh,.. hmm
434 [13:20] stevan sort of like inflate/deflate?
435 [13:20] stevan around the accessors?
436 [13:25] * bluefeet has quit (Remote host closed the connection)
437 [13:27] mst no
438 [13:27] mst nothing like that
439 [13:27] mst like a cast
440 [13:31] mst stevan: $obj->foo($bar); where 'foo' expects a 'Foo' object
441 [13:31] mst stevan: is effectively <Foo>$bar, right?
442 [13:32] mst stevan: I want to be able to say in package Bar
443 [13:32] mst stevan: coerce_to 'Foo' via { ... };
444 [13:32] mst etc.
445 [13:53] stevan hmm
446
447### add support for locally scoped TC
f3dc2e80 448
449This would borrow from MooseX::TypeLibrary to prefix the TC with the name
450of the package. It would then be accesible from the outside as the fully
451scoped name, but the local attributes would use it first. (this would need support
452in the registry for this).
453
6e6a1027 454### look into sugar extensions
f3dc2e80 455
456Use roles as sugar layer function providers (ala MooseX::AttributeHelpers). This
457would allow custom metaclasses to provide roles to extend the sugar syntax with.
458
459(NOTE: Talk to phaylon a bit more on this)
460
6e6a1027 461### allow a switch of some kind to optionally turn TC checking off at runtime
f3dc2e80 462
463The type checks can get expensive and some people have suggested that allowing
464the checks to be turned off would be helpful for deploying into performance
ea8e79f1 465intensive systems. Perhaps this can actually be done as an option to `make_immutable`?
f3dc2e80 466
6e6a1027 467### misc. minor bits
f3dc2e80 468
ea8e79f1 469* make the errors for TCs use `->message`
f3dc2e80 470* look into localizing the messages too
471* make ANON TCs be lazy, so they can possibly be subsituted for the real thing later
472* make ANON TCs more introspectable
473* add this ...
474
6e6a1027 475 subtype 'Username',
476 from 'Str',
477 where { (/[a-z][a-z0-9]+/i or fail('Invalid character(s)'))
478 and (length($_) >= 5 or fail('Too short (less than 5 chars)'))
479 }
480 on_fail { MyException->throw(value => $_[0], message => $_[1]) };
f3dc2e80 481
ea8e79f1 482fail() will just return false unless the call is made via `$tc->check_or_fail($value);`
f3dc2e80 483
484* and then something like this:
485
6e6a1027 486 subtype Foo => as Bar => where { ... } => scoped => -global;
487 subtype Foo => as Bar => where { ... } => scoped => -local;
f3dc2e80 488
6e6a1027 489 # or
f3dc2e80 490
6e6a1027 491 subtype Foo => as Bar => where { ... } => in __PACKAGE__ ;
f3dc2e80 492
6e6a1027 493 # or (not sure if it would be possible)
f3dc2e80 494
6e6a1027 495 my $Foo = subtype Bar => where { ... };
f3dc2e80 496
6e6a1027 497### Deep coercion?
f3dc2e80 498
6e6a1027 499 [17:10] <autarch> stevan: it should do it if I pass coerce => 1 as part of the attribute definition
500 [17:12] <stevan> autarch: what I am not 100% sure of is how to tell it to deep coerce and when to not
501 [17:13] <stevan> cause a basic coerce is from A to B
502 [17:13] <autarch> hmm
503 [17:13] <stevan> which is valid for collection types too
504 [17:13] <stevan> deep coercion is what you are asking for
505 [17:13] <autarch> yeah
506 [17:13] <stevan> so perhaps we add deep_coerce => 1
507 [17:13] <stevan> which will do it
508 [17:13] <autarch> that's fine for me
509 [17:13] <stevan> k
f3dc2e80 510
ea8e79f1 511`coerce_deeply => 1 # reads better`
f3dc2e80 512
6e6a1027 513### Moose::Meta::TypeConstraint::Parameter{izable,ized}
7af2c1d2 514
515The relationship between these two classes is very odd. In particular,
516this line in Parameterized is insane:
517
518 foreach my $type (Moose::Util::TypeConstraints::get_all_parameterizable_types()) {
519
520Why does it need to loop through all parameterizable types? Shouldn't
521it know which parameterizable type it "came from"?