1Class::MethodMaker::V1CUosmepratC(o3n)tributed Perl DocuCmleanstsa:t:iMoenthodMaker::V1Compat(3)
2
3
4

NAME

6       Class::MethodMaker::V1Compat - V1 compatibility code for C::MM
7

SYNOPSIS

9       This class is for internal implementation only.  It is not a public
10       API.
11

DESCRIPTION

13       Class::MethodMaker version 2 strives for backward-compatiblity with
14       version 1 as far as possible.  That is to say, classes built with ver‐
15       sion 1 should work with few if any changes.  However, the calling con‐
16       ventions for building new classes are significantly different: this is
17       necessary to achieve a greater consistency of arguments.
18
19       Version 2 takes all arguments within a single arrayref:
20
21         use Class::MethodMaker
22           [ scalar => 'a' ];
23
24       If arguments are presented as a list, then Class::MethodMaker assumes
25       that this is a version 1 call, and acts accordingly.  Version 1 argu‐
26       ments are passed and internally rephrased to version 2 arguments, and
27       passed off to the version 2 engine.  Thus, the majority of version 1
28       calls can be upgraded to version 2 merely by rephrasing.  However,
29       there are a number of behaviours that in version 1 that are internally
30       inconsistent.  These behaviours are mimicked in version 1 mode as far
31       as possible, but are not reproducible in version 2 (to allow version 2
32       clients to rely on a more internally consistent interface).
33
34       Version 2 Implementations
35
36       The nearest equivalent to each 1 component (slot) available in version
37       2 is shown below using the indicated data-structures & options to cre‐
38       ate a component called "a" that mimicks the V1 component behaviour as
39       closely as possible:
40
41       abstract
42             use Class::MethodMaker
43               [ abstract => 'a' ];
44
45       boolean
46           Boolean is available as a backwards compatiblity hack, but there is
47           currently no V2 equivalent.  It is likely that some replacement
48           mechanism will be introduced in the future, but that it will be
49           incompatible with the version 1 boolean.
50
51       code
52             use Class::MethodMaker
53               [ scalar => 'a' ];
54
55           Let's face it, the v1 store-if-it's-a-coderef-else-retrieve seman‐
56           tics are rather broken.  How do you pass a coderef as argument to
57           one of these?  It is on the TODO list to recognize code as funda‐
58           mental restricted type (analogous to INTEGER), which would add in a
59           *_invoke method.
60
61       copy
62             use Class::MethodMaker
63               [ copy => 'a' ];
64
65           The v2 method is the same as v1.
66
67       counter
68             use Class::MethodMaker
69               [ scalar => [{-type => Class::MethodMaker::Constants::INTEGER}, 'a'] ];
70
71       copy
72       deep_copy
73             use Class::MethodMaker
74               [ copy => [ -deep => 'a' ] ];
75
76       get_concat
77             use Class::MethodMaker
78               [ scalar => [{ -store_cb => sub {
79                                             defined $_[1] ? ( defined $_[3] ?
80                                                               "$_[3] $_[1]" : $_[1] )
81                                                           : undef;
82                                           }
83                            },
84                            'a' ]
85               ];
86
87       get_set
88             use Class::MethodMaker
89               [ scalar => 'a' ];
90
91       hash
92             use Class::MethodMaker
93               [ hash => 'a' ];
94
95       key_attrib
96           Although v1 calls will continue to work, this is not supported in
97           v2.
98
99       key_with_create
100           Although v1 calls will continue to work, this is not supported in
101           v2.
102
103       list
104             use Class::MethodMaker
105               [ list => 'a' ];
106
107           Note that the "*" method now sets the whole array if given argu‐
108           ments.
109
110       method
111           See "code".
112
113       new
114             use Class::MethodMaker
115               [ new => 'a' ];
116
117       new_hash_init
118             use Class::MethodMaker
119               [ new => [ -hash => 'a' ] ];
120
121       new_hash_with_init
122             use Class::MethodMaker
123               [ new => [ -hash => -init => 'a' ] ];
124
125       new_with_args
126           Although v1 calls will continue to work, this is not supported in
127           v2, for it is a trivial application of "new_with_init".
128
129       new_with_init
130             use Class::MethodMaker
131               [ new => [ -init => 'a' ] ];
132
133       object
134             use Class::MethodMaker
135               [ scalar => [{ -type    => 'MyClass',
136                              -forward => [qw/ method1 method2 /] }, 'a' ]
137               ];
138
139       object_tie_hash
140             use Class::MethodMaker
141               [ hash => [{ -type      => 'MyClass',
142                            -forward   => [qw/ method1 method2 /],
143                            -tie_class => 'Tie::MyTie',
144                            -tie_args  => [qw/ foo bar baz /],
145                          }, 'a' ]
146               ];
147
148       object_tie_list
149             use Class::MethodMaker
150               [ array => [{ -type      => 'MyClass',
151                             -forward   => [qw/ method1 method2 /],
152                             -tie_class => 'Tie::MyTie',
153                             -tie_args  => [qw/ foo bar baz /],
154                           }, 'a' ]
155               ];
156
157       set_once
158             use Class::MethodMaker
159               [ scalar => [{ -store_cb => sub {
160                                             die "Already stored $_[3]"
161                                               if @_ > 3;
162                                           }
163                            },
164                            'a' ]
165               ];
166
167       set_once_static
168             use Class::MethodMaker
169               [ scalar => [{ -store_cb => sub {
170                                             die "Already stored $_[3]"
171                                               if @_ > 3;
172                                           },
173                              -static   => 1,
174                            },
175                            'a' ]
176               ];
177
178       singleton
179             use Class::MethodMaker
180               [ new => [ -singleton => -hash => -init => 'a' ] ];
181
182       static_get_set
183             use Class::MethodMaker
184               [ scalar => [ -static => 'a' ], ];
185
186       static_hash
187             use Class::MethodMaker
188               [ hash => [ -static => 'a' ], ];
189
190       static_list
191             use Class::MethodMaker
192               [ list => [ -static => 'a' ], ];
193
194       tie_hash
195             use Class::MethodMaker
196               [ hash => [ { -tie_class => 'MyTie',
197                             -tie_args  => [qw/ foo bar baz /],
198                           } => 'a' ], ];
199
200       tie_list
201             use Class::MethodMaker
202               [ array => [ { -tie_class => 'MyTie',
203                              -tie_args  => [qw/ foo bar baz /],
204                            } => 'a' ], ];
205
206       tie_scalar
207             use Class::MethodMaker
208               [ scalar => [ { -tie_class => 'MyTie',
209                               -tie_args  => [qw/ foo bar baz /],
210                             } => 'a' ], ];
211
212       Caveats & Expected Breakages
213
214       The following version 1 component (slot) types are not currently sup‐
215       ported in version 2:
216
217       grouped_fields
218       hash_of_lists
219       listed_attrib
220       struct
221

EXAMPLES

223
224

BUGS

226
227

REPORTING BUGS

229       Email the development mailing list "class-mmaker-devel@lists.source‐
230       forge.net".
231

AUTHOR

233       Martyn J. Pearce
234
236       Copyright (c) 2003, 2004 Martyn J. Pearce.  This program is free soft‐
237       ware; you can redistribute it and/or modify it under the same terms as
238       Perl itself.
239

SEE ALSO

241
242
243
244
245perl v5.8.8                       2005-11-26   Class::MethodMaker::V1Compat(3)
Impressum