1 package Package::DeprecationManager;
7 use Params::Util qw( _HASH );
15 'You must provide a hash reference -deprecations parameter when importing Package::DeprecationManager'
16 unless $args{-deprecations} && _HASH( $args{-deprecations} );
20 my $import = _build_import( \%registry );
21 my $warn = _build_warn( \%registry, $args{-deprecations} );
23 my $caller = caller();
25 Sub::Install::install_sub(
33 Sub::Install::install_sub(
51 $args{-api_version} ||= delete $args{-compatible};
53 $registry->{ caller() } = $args{-api_version}
54 if $args{-api_version};
62 my $deprecated_at = shift;
67 my ( $package, undef, undef, $sub ) = caller(1);
69 my $compat_version = $registry->{$package};
71 my $deprecated_at = $deprecated_at->{$sub};
74 if defined $compat_version
75 && defined $deprecated_at
76 && $compat_version lt $deprecated_at;
78 return if $warned{$package}{$sub};
81 my $msg = "$sub has been deprecated";
82 $msg .= " since version $deprecated_at"
83 if defined $deprecated_at;
88 $warned{$package}{$sub} = 1;
96 # ABSTRACT: Manage deprecation warnings for your distribution
106 use Package::DeprecationManager
108 'My::Class::foo' => '0.02',
109 'My::Class::bar' => '0.05',
113 deprecated( 'Do not call foo!' );
124 package Other::Class;
126 use My::Class -api_version => '0.04';
128 My::Class->new()->foo(); # warns
129 My::Class->new()->bar(); # does not warn
130 My::Class->new()->far(); # does not warn again
134 This module allows you to manage a set of deprecations for one or more modules.
136 When you import C<Package::DeprecationManager>, you must provide a set of
137 C<-deprecations> as a hash ref. The keys are fully qualified sub/method names,
138 and the values are the version when that subroutine was deprecated.
140 As part of the import process, C<Package::DeprecationManager> will export two
141 subroutines into its caller. It proves an C<import()> sub for the caller and a
144 The C<import()> sub allows callers of I<your> class to specify an C<-api_version>
145 parameter. If this is supplied, then deprecation warnings are only issued for
146 deprecations for api versions earlier than the one specified.
148 You must call C<deprecated()> sub in each deprecated subroutine. When called,
149 it will issue a warning using C<Carp::cluck()>. If you do not pass an explicit
150 warning message, one will be generated for you.
152 Deprecation warnings are only issued once for a given package, regardless of
153 how many times the deprecated sub/method is called.
157 Please report any bugs or feature requests to
158 C<bug-package-deprecationmanager@rt.cpan.org>, or through the web interface at
159 L<http://rt.cpan.org>. I will be notified, and then you'll automatically be
160 notified of progress on your bug as I make changes.
164 If you'd like to thank me for the work I've done on this module, please
165 consider making a "donation" to me via PayPal. I spend a lot of free time
166 creating free software, and would appreciate any support you'd care to offer.
168 Please note that B<I am not suggesting that you must do this> in order
169 for me to continue working on this particular software. I will
170 continue to do so, inasmuch as I have in the past, for as long as it
173 Similarly, a donation made in this way will probably not make me work on this
174 software much more, unless I get so many donations that I can consider working
175 on free software full time, which seems unlikely at best.
177 To donate, log into PayPal and send money to autarch@urth.org or use the
178 button on this page: L<http://www.urth.org/~autarch/fs-donation.html>
182 The idea for this functionality and some of its implementation was originally
183 created as L<Class::MOP::Deprecated> by Goro Fuji.