Commit | Line | Data |
30229767 |
1 | package Class::MOP::Deprecated; |
2 | |
3 | use strict; |
4 | use warnings; |
b409c969 |
5 | |
6 | use Carp qw( cluck ); |
7 | use Scalar::Util qw( blessed ); |
30229767 |
8 | |
f6ca0704 |
9 | our $VERSION = '0.94'; |
30229767 |
10 | $VERSION = eval $VERSION; |
11 | our $AUTHORITY = 'cpan:STEVAN'; |
12 | |
13 | my %DeprecatedAt = ( |
14 | |
15 | # features deprecated before 0.93 |
16 | 'Class::MOP::HAVE_ISAREV' => 0.93, |
17 | 'Class::MOP::subname' => 0.93, |
18 | 'Class::MOP::in_global_destruction' => 0.93, |
19 | |
241646a3 |
20 | 'Class::MOP::Package::get_method_map' => 0.93, |
21 | |
30229767 |
22 | 'Class::MOP::Class::construct_class_instance' => 0.93, |
23 | 'Class::MOP::Class::check_metaclass_compatibility' => 0.93, |
24 | 'Class::MOP::Class::create_meta_instance' => 0.93, |
25 | 'Class::MOP::Class::clone_instance' => 0.93, |
26 | 'Class::MOP::Class::alias_method' => 0.93, |
27 | 'Class::MOP::Class::compute_all_applicable_methods' => 0.93, |
28 | 'Class::MOP::Class::compute_all_applicable_attributes' => 0.93, |
29 | |
30 | 'Class::MOP::Instance::bless_instance_structure' => 0.93, |
31 | |
32 | 'Class::MOP::Attribute::process_accessors' => 0.93, |
33 | |
34 | 'Class::MOP::Method::Accessor::initialize_body' => 0.93, |
35 | 'Class::MOP::Method::Accessor::generate_accessor_method' => 0.93, |
36 | 'Class::MOP::Method::Accessor::generate_reader_method' => 0.93, |
37 | 'Class::MOP::Method::Accessor::generate_writer_method' => 0.93, |
38 | 'Class::MOP::Method::Accessor::generate_predicate_method' => 0.93, |
39 | 'Class::MOP::Method::Accessor::generate_clearer_method' => 0.93, |
40 | 'Class::MOP::Method::Accessor::generate_accessor_method_inline' => 0.93, |
41 | 'Class::MOP::Method::Accessor::generate_reader_method_inline' => 0.93, |
42 | 'Class::MOP::Method::Accessor::generate_writer_method_inline' => 0.93, |
43 | 'Class::MOP::Method::Accessor::generate_clearer_method_inline' => 0.93, |
44 | 'Class::MOP::Method::Accessor::generate_predicate_method_inline' => 0.93, |
45 | |
46 | 'Class::MOP::Method::Constructor::meta_instance' => 0.93, |
47 | 'Class::MOP::Method::Constructor::attributes' => 0.93, |
48 | 'Class::MOP::Method::Constructor::initialize_body' => 0.93, |
49 | 'Class::MOP::Method::Constructor::generate_constructor_method' => 0.93, |
50 | 'Class::MOP::Method::Constructor::generate_constructor_method_inline' => |
51 | 0.93, |
52 | |
53 | # features deprecated after 0.93 |
54 | # ... |
55 | ); |
56 | |
57 | my %Registry; |
58 | |
59 | sub import { |
60 | my ( $class, %args ) = @_; |
61 | |
62 | if ( defined( my $compat_version = delete $args{-compatible} ) ) { |
63 | $Registry{ (caller) } = $compat_version; |
64 | } |
65 | |
66 | if (%args) { |
67 | my $unknowns = join q{ }, keys %args; |
68 | cluck "Unknown argument(s) for $class->import: $unknowns.\n"; |
69 | } |
70 | return; |
71 | } |
72 | |
73 | sub warn { |
74 | my ( $package, undef, undef, $feature ) = caller(1); |
75 | |
76 | my $compat_version; |
77 | while ( $package && !defined( $compat_version = $Registry{$package} ) ) { |
78 | $package =~ s/ :: \w+ \z//xms or last; |
79 | } |
80 | |
81 | my $deprecated_at = $DeprecatedAt{$feature} |
82 | or die "Unregistered deprecated feature: $feature"; |
83 | |
84 | if ( !defined($compat_version) |
85 | || $compat_version >= $DeprecatedAt{$feature} ) { |
86 | goto &cluck; |
87 | } |
88 | } |
89 | |
90 | package |
91 | Class::MOP; |
92 | |
93 | sub HAVE_ISAREV () { |
94 | Class::MOP::Deprecated::warn( |
95 | "Class::MOP::HAVE_ISAREV is deprecated and will be removed in a future release. It has always returned 1 anyway." |
96 | ); |
97 | return 1; |
98 | } |
99 | |
100 | sub subname { |
101 | Class::MOP::Deprecated::warn( |
102 | "Class::MOP::subname is deprecated. Please use Sub::Name directly."); |
103 | require Sub::Name; |
104 | goto \&Sub::Name::subname; |
105 | } |
106 | |
107 | sub in_global_destruction { |
108 | Class::MOP::Deprecated::warn( |
109 | "Class::MOP::in_global_destruction is deprecated. Please use Devel::GlobalDestruction directly." |
110 | ); |
111 | require Devel::GlobalDestruction; |
112 | goto \&Devel::GlobalDestruction::in_global_destruction; |
113 | } |
114 | |
115 | package |
116 | Class::MOP::Package; |
117 | |
b409c969 |
118 | sub get_method_map { |
119 | Class::MOP::Deprecated::warn( |
120 | 'The get_method_map method has been made private.' |
121 | . " The public version is deprecated and will be removed in a future release.\n" |
122 | ); |
123 | my $self = shift; |
124 | |
125 | my $map = $self->_full_method_map; |
126 | |
127 | $map->{$_} = $self->get_method($_) |
128 | for grep { !blessed( $map->{$_} ) } keys %{$map}; |
129 | |
130 | return $map; |
131 | } |
132 | |
30229767 |
133 | package |
134 | Class::MOP::Module; |
135 | |
136 | package |
137 | Class::MOP::Class; |
138 | |
139 | sub construct_class_instance { |
140 | Class::MOP::Deprecated::warn( |
141 | 'The construct_class_instance method has been made private.' |
142 | . " The public version is deprecated and will be removed in a future release.\n" |
143 | ); |
144 | shift->_construct_class_instance(@_); |
145 | } |
146 | |
147 | sub check_metaclass_compatibility { |
148 | Class::MOP::Deprecated::warn( |
149 | 'The check_metaclass_compatibility method has been made private.' |
150 | . " The public version is deprecated and will be removed in a future release.\n" |
151 | ); |
152 | shift->_check_metaclass_compatibility(@_); |
153 | } |
154 | |
155 | sub construct_instance { |
156 | Class::MOP::Deprecated::warn( |
157 | 'The construct_instance method has been made private.' |
158 | . " The public version is deprecated and will be removed in a future release.\n" |
159 | ); |
160 | shift->_construct_instance(@_); |
161 | } |
162 | |
163 | sub create_meta_instance { |
164 | Class::MOP::Deprecated::warn( |
165 | 'The create_meta_instance method has been made private.' |
166 | . " The public version is deprecated and will be removed in a future release.\n" |
167 | ); |
168 | shift->_create_meta_instance(@_); |
169 | } |
170 | |
171 | sub clone_instance { |
172 | Class::MOP::Deprecated::warn( |
173 | 'The clone_instance method has been made private.' |
174 | . " The public version is deprecated and will be removed in a future release.\n" |
175 | ); |
176 | shift->_clone_instance(@_); |
177 | } |
178 | |
179 | sub alias_method { |
180 | Class::MOP::Deprecated::warn( |
181 | "The alias_method method is deprecated. Use add_method instead.\n"); |
182 | |
183 | shift->add_method(@_); |
184 | } |
185 | |
186 | sub compute_all_applicable_methods { |
187 | Class::MOP::Deprecated::warn( |
188 | 'The compute_all_applicable_methods method is deprecated.' |
189 | . " Use get_all_methods instead.\n" ); |
190 | |
191 | return map { |
192 | { |
193 | name => $_->name, |
194 | class => $_->package_name, |
195 | code => $_, # sigh, overloading |
196 | }, |
197 | } shift->get_all_methods(@_); |
198 | } |
199 | |
200 | sub compute_all_applicable_attributes { |
201 | Class::MOP::Deprecated::warn( |
202 | 'The compute_all_applicable_attributes method has been deprecated.' |
203 | . " Use get_all_attributes instead.\n" ); |
204 | |
205 | shift->get_all_attributes(@_); |
206 | } |
207 | |
208 | package |
209 | Class::MOP::Instance; |
210 | |
211 | sub bless_instance_structure { |
212 | Class::MOP::Deprecated::warn( |
213 | 'The bless_instance_structure method is deprecated.' |
214 | . " It will be removed in a future release.\n" ); |
215 | |
216 | my ( $self, $instance_structure ) = @_; |
217 | bless $instance_structure, $self->_class_name; |
218 | } |
219 | |
220 | package |
221 | Class::MOP::Attribute; |
222 | |
223 | sub process_accessors { |
224 | Class::MOP::Deprecated::warn( |
225 | 'The process_accessors method has been made private.' |
226 | . " The public version is deprecated and will be removed in a future release.\n" |
227 | ); |
228 | shift->_process_accessors(@_); |
229 | } |
230 | |
231 | package |
232 | Class::MOP::Method::Accessor; |
233 | |
234 | sub initialize_body { |
235 | Class::MOP::Deprecated::warn( |
236 | 'The initialize_body method has been made private.' |
237 | . " The public version is deprecated and will be removed in a future release.\n" |
238 | ); |
239 | shift->_initialize_body; |
240 | } |
241 | |
242 | sub generate_accessor_method { |
243 | Class::MOP::Deprecated::warn( |
244 | 'The generate_accessor_method method has been made private.' |
245 | . " The public version is deprecated and will be removed in a future release.\n" |
246 | ); |
247 | shift->_generate_accessor_method; |
248 | } |
249 | |
250 | sub generate_reader_method { |
251 | Class::MOP::Deprecated::warn( |
252 | 'The generate_reader_method method has been made private.' |
253 | . " The public version is deprecated and will be removed in a future release.\n" |
254 | ); |
255 | shift->_generate_reader_method; |
256 | } |
257 | |
258 | sub generate_writer_method { |
259 | Class::MOP::Deprecated::warn( |
260 | 'The generate_writer_method method has been made private.' |
261 | . " The public version is deprecated and will be removed in a future release.\n" |
262 | ); |
263 | shift->_generate_writer_method; |
264 | } |
265 | |
266 | sub generate_predicate_method { |
267 | Class::MOP::Deprecated::warn( |
268 | 'The generate_predicate_method method has been made private.' |
269 | . " The public version is deprecated and will be removed in a future release.\n" |
270 | ); |
271 | shift->_generate_predicate_method; |
272 | } |
273 | |
274 | sub generate_clearer_method { |
275 | Class::MOP::Deprecated::warn( |
276 | 'The generate_clearer_method method has been made private.' |
277 | . " The public version is deprecated and will be removed in a future release.\n" |
278 | ); |
279 | shift->_generate_clearer_method; |
280 | } |
281 | |
282 | sub generate_accessor_method_inline { |
283 | Class::MOP::Deprecated::warn( |
284 | 'The generate_accessor_method_inline method has been made private.' |
285 | . " The public version is deprecated and will be removed in a future release.\n" |
286 | ); |
287 | shift->_generate_accessor_method_inline; |
288 | } |
289 | |
290 | sub generate_reader_method_inline { |
291 | Class::MOP::Deprecated::warn( |
292 | 'The generate_reader_method_inline method has been made private.' |
293 | . " The public version is deprecated and will be removed in a future release.\n" |
294 | ); |
295 | shift->_generate_reader_method_inline; |
296 | } |
297 | |
298 | sub generate_writer_method_inline { |
299 | Class::MOP::Deprecated::warn( |
300 | 'The generate_writer_method_inline method has been made private.' |
301 | . " The public version is deprecated and will be removed in a future release.\n" |
302 | ); |
303 | shift->_generate_writer_method_inline; |
304 | } |
305 | |
306 | sub generate_predicate_method_inline { |
307 | Class::MOP::Deprecated::warn( |
308 | 'The generate_predicate_method_inline method has been made private.' |
309 | . " The public version is deprecated and will be removed in a future release.\n" |
310 | ); |
311 | shift->_generate_predicate_method_inline; |
312 | } |
313 | |
314 | sub generate_clearer_method_inline { |
315 | Class::MOP::Deprecated::warn( |
316 | 'The generate_clearer_method_inline method has been made private.' |
317 | . " The public version is deprecated and will be removed in a future release.\n" |
318 | ); |
319 | shift->_generate_clearer_method_inline; |
320 | } |
321 | |
322 | package |
323 | Class::MOP::Method::Constructor; |
324 | |
325 | sub meta_instance { |
326 | Class::MOP::Deprecated::warn( |
327 | 'The meta_instance method has been made private.' |
328 | . " The public version is deprecated and will be removed in a future release.\n" |
329 | ); |
330 | shift->_meta_instance; |
331 | } |
332 | |
333 | sub attributes { |
334 | Class::MOP::Deprecated::warn( |
335 | 'The attributes method has been made private.' |
336 | . " The public version is deprecated and will be removed in a future release.\n" |
337 | ); |
338 | |
339 | return shift->_attributes; |
340 | } |
341 | |
342 | sub initialize_body { |
343 | Class::MOP::Deprecated::warn( |
344 | 'The initialize_body method has been made private.' |
345 | . " The public version is deprecated and will be removed in a future release.\n" |
346 | ); |
347 | shift->_initialize_body; |
348 | } |
349 | |
350 | sub generate_constructor_method { |
351 | Class::MOP::Deprecated::warn( |
352 | 'The generate_constructor_method method has been made private.' |
353 | . " The public version is deprecated and will be removed in a future release.\n" |
354 | ); |
355 | shift->_generate_constructor_method; |
356 | } |
357 | |
358 | sub generate_constructor_method_inline { |
359 | Class::MOP::Deprecated::warn( |
360 | 'The generate_constructor_method_inline method has been made private.' |
361 | . " The public version is deprecated and will be removed in a future release.\n" |
362 | ); |
363 | shift->_generate_constructor_method_inline; |
364 | } |
365 | |
366 | 1; |
367 | |
368 | __END__ |
369 | |
370 | =pod |
371 | |
372 | =head1 NAME |
373 | |
374 | Class::MOP::Deprecated - List of deprecated methods |
375 | |
376 | =head1 DESCRIPTION |
377 | |
378 | use Class::MOP::Deprecated -compatible => $version; |
379 | |
380 | =head1 FUNCTIONS |
381 | |
b409c969 |
382 | This class provides methods that have been deprecated but remain for backward |
383 | compatibility. |
30229767 |
384 | |
b409c969 |
385 | If you specify C<< -compatible => $version >>, you can use deprecated features |
386 | without warnings. Note that this special treatment is limited to the package |
387 | that loads C<Class::MOP::Deprecated>. |
30229767 |
388 | |
389 | =head1 AUTHORS |
390 | |
391 | Goro Fuji E<lt>gfuji@cpan.orgE<gt> |
392 | |
393 | =head1 COPYRIGHT AND LICENSE |
394 | |
395 | Copyright 2006-2009 by Infinity Interactive, Inc. |
396 | |
397 | L<http://www.iinteractive.com> |
398 | |
399 | This library is free software; you can redistribute it and/or modify |
400 | it under the same terms as Perl itself. |
401 | |
402 | =cut |