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