TypeConstraint::Utils,.. now with find_or_create_type_constraint goodness
[gitmo/Moose.git] / PLANS
1 -----------------------------------------------------------
2 -- Type Constraints refactor
3 -----------------------------------------------------------
4
5 - move the details of TC construction that are in Moose.pm and 
6   Moose::Util::TypeConstraints into the Moose::Meta::TypeConstraint module
7
8 This will make it much easier to generate TCs on their own, without 
9 having to use the sugar layer. This should also clean up their APIs 
10 as well, which will make it easier to subclass them.
11
12 - allow a switch of some kind to optionally turn TC checking off at runtime 
13
14 The type checks can get expensive and some people have suggested that allowing 
15 the checks to be turned off would be helpful for deploying into performance 
16 intensive systems. Perhaps this can actually be done as an option to make_immutable? 
17
18 - add support for locally scoped TC
19
20 This would borrow from MooseX::TypeLibrary to prefix the TC with the name 
21 of the package. It would then be accesible from the outside as the fully 
22 scoped name, but the local attributes would use it first. (this would need support 
23 in the registry for this).
24
25 - look into sugar extensions
26
27 Use roles as sugar layer function providers (ala MooseX::AttributeHelpers). This 
28 would allow custom metaclasses to provide roles to extend the sugar syntax with.
29
30 (NOTE: Talk to phaylon a bit more on this)
31
32 - misc. minor bits
33
34 * make the errors for TCs use ->message
35 * look into localizing the messages too
36 * make ANON TCs be lazy, so they can possibly be subsituted for the real thing later
37 * make ANON TCs more introspectable
38 * add this ...
39
40 #
41 #   Type Definition
42 #
43 subtype 'Username',
44    from 'Str',
45   where {     (/[a-z][a-z0-9]+/i or fail('Invalid character(s)'))
46           and (length($_) >= 5   or fail('Too short (less than 5 chars)'))
47         }
48 on_fail { MyException->throw(value => $_[0], message => $_[1]) };
49
50 # fail() will just return false unless the call is made via
51 $tc->check_or_fail($value);
52
53 * and then something like this:
54
55 subtype Foo => as Bar => where { ... } => scoped => -global;
56 subtype Foo => as Bar => where { ... } => scoped => -local; 
57
58 # or 
59
60 subtype Foo => as Bar => where { ... } => in __PACKAGE__ ; 
61
62 # or (not sure if it would be possible)
63
64 my $Foo = subtype Bar => where { ... };
65
66 # ----------
67
68 [17:10]  <autarch> stevan: it should do it if I pass coerce => 1 as part of the attribute definition
69 [17:12]  <stevan> autarch: what I am not 100% sure of is how to tell it to deep coerce and when to not 
70 [17:13]  <stevan> cause a basic coerce is from A to B
71 [17:13]  <autarch> hmm
72 [17:13]  <stevan> which is valid for collection types too
73 [17:13]  <stevan> deep coercion is what you are asking for
74 [17:13]  <autarch> yeah
75 [17:13]  <stevan> so perhaps we add deep_coerce => 1
76 [17:13]  <stevan> which will do it
77 [17:13]  <autarch> that's fine for me
78 [17:13]  <stevan> k
79
80 -----------------------------------------------------------
81 - TC stuff DONE
82 -----------------------------------------------------------
83
84 - create an official TC registry API (DONE)
85
86 Right now the registration of the TC is a by-product of creation in the sugar 
87 layer, this is bad and make extension of TCs difficult. I am not sure if this 
88 registry API should exist as part of Moose::Util::TypeConstraints, or of we 
89 should create a complete registry object itself. 
90
91 This registry should be a singleton, but M::U::TC should enforce that lifecycle 
92 choice so that you can use your own registry if you really want too.
93
94 I mean parent of the registry. So that I can create my own registry
95 object for a given class, and any retrieval of a type constraint from
96 this object would automatically search parent registries as well.
97
98 - refactor the various TC internals to make it more subclassing friendly (DONE)
99
100 This also includes the coercion stuff as well. This should give you what you 
101 need to make your object/class bound stuff.
102
103 - move the container TCs from MooseX::AttributeHelpers into Moose core (DONE)
104
105 These have proven so useful for me in the latest $work project that I think 
106 they should really be core.
107
108 -----------------------------------------------------------
109 -- Roles refactor
110 -----------------------------------------------------------
111
112
113 -----------------------------------------------------------
114 -- Immutable refactor
115 -----------------------------------------------------------