Commit | Line | Data |
6af1e11b |
1 | =head1 MIGRATION GUIDE |
2 | |
3 | So you want to migrate your wonderful MooseX::AttributeHelpers code to the |
4 | new and shiny L<Moose::Meta::Attribute::Native>? Then you've come to the |
5 | right place at least :) |
6 | |
7 | =head2 DIFFERENCES |
8 | |
9 | There are some subtle differences between the two, and we will try to hilight |
10 | them with small code snipptes |
11 | |
12 | First a MX::AH example: |
13 | |
14 | use Moose; |
15 | use MooseX::AttributeHelpers; |
16 | |
17 | has 'items' => ( |
18 | metaclass => 'Collection::List', |
19 | is => 'ro', |
20 | isa => 'ArrayRef', |
21 | provides => { |
22 | 'grep' => 'filter_items', |
23 | } |
24 | ); |
25 | |
26 | And now the updated way using the Native traits from Moose it self |
27 | |
28 | use Moose; |
29 | |
30 | has 'items' => ( |
31 | traits => ['Array'], |
32 | is => 'ro', |
33 | isa => 'ArrayRef', |
34 | handles => { |
35 | 'filter_items' => 'grep', |
36 | }, |
37 | ); |
38 | |
39 | There are basicly three diffrences in the simple cases. |
40 | |
41 | =over |
42 | |
43 | =item metaclass becomes trait |
44 | |
45 | In the native way of doing things, we add a trait to our attribute, where |
46 | we in AttributeHelpers assigned a metaclass. |
47 | |
48 | =item provides is removed in favour of the standard handles |
49 | |
50 | Where we used to have a special syntax for method provides in the old way |
51 | of doing things, we now use the standard handles in the native way. There is |
52 | one noteable exception to the usual handles in has (), which is that for |
53 | the Native traits, we only accept a hashref. |
54 | |
55 | This leads us over to the last difference of the day |
56 | |
57 | =item the order of handles is the reversed order of provides |
58 | |
59 | You might have spotted this already, you clever you? This is done |
60 | to conform to the standard way handles works, and should make it easier |
61 | and clearer in the long run. |
62 | |