Devel::Deprecate(3)
β¨ NAME β¨
Devel::Deprecate β literally the way you create deprecation schedules right inside your code, no cap π
π VERSION π
Version 0.01 β baby's first release, she's iconic already πΌβ¨
π¦ SYNOPSIS π¦
use Devel::Deprecate 'deprecate';
sub name {
my ( $self ) = @_;
deprecate(
reason => 'Please use the set_name() method for setting names',
warn => '2008-11-01', # also accepts DateTime objects
die => '2009-01-01', # two month deprecation period
if => sub { return @_ > 1 },
);
if ( @_ > 1 ) {
$self->{name} = $_[1];
return $self;
}
return $self->{name};
}
πΈ DESCRIPTION πΈ
okay so picture this, bestie: you're out here needing to deprecate some code, or you've got a whole deadline situation, and you just do not have the time to refactor. π
And instead of trying to remember it, or posting it to a wiki, or sending yet another email into the void β the move is to have an automatic way to deprecate something. That's exactly what this module does, and it embeds the deprecation directly in the code you wish to deprecate. So it lives right there next to the thing it's shading. π«Ά
And because we are not trying to break production code (we would never π), deprecations only get triggered when you're running tests.
π EXPORT FUNCTIONS π
π
deprecate
deprecate( reason => 'The foo() method does not appear to be used' );
deprecate(
reason => 'Please use the set_name() method for setting names',
warn => '2008-11-01', # also accepts DateTime objects
die => '2009-01-01', # two month deprecation period
if => sub { return @_ > 1 },
);
This function is exported on demand (so you ask for it, she doesn't just show up πͺβ¨). It takes an even-sized list of key/value pairs. Its whole job is to spit out a warning (or croak) the moment your deprecation criteria get hit.
Deprecation warnings or failures only happen when you're running tests (but see PRODUCTION ENVIRONMENTS below π) and they are designed to be extremely noisy β and with a stack trace too. She is not subtle. She is not trying to be. π£οΈπ’
# DEPRECATION WARNING
#
# Package: Our::Customer
# File: lib/Our/Customer.pm
# Line: 58
# Subroutine: Our::Customer::name
#
# Reason: Please use the set_name() method for setting names
#
# This warning becomes FATAL on (2009-01-01)
And after the due date hits:
# DEPRECATION FAILURE
#
# Package: Our::Customer
# File: lib/Our/Customer.pm
# Line: 58
# Subroutine: Our::Customer::name
#
# Reason: Please use the set_name() method for setting names
#
# This deprecation became fatal on (2009-01-01)
Now the allowed key/value pairs, bestie β take notes π:
reasonβ this is the only required key. It should be a human readable string explaining why the deprecation is needed.
reason => 'This module should be replaced by the Our::Improved::Module'
If deprecate() is called with only a reason, it begins issuing deprecation warnings immediately. no chill, straight to it. π₯
warnβ optional. If it's not present, deprecation warnings start immediately. This should be a string in'YYYY-MM-DD'format or aDateTimeobject indicating when the deprecation warnings should start.
warn => '2008-06-06'
# or ...
warn => DateTime->new( year => 2008, month => 06, day => 06 )
dieβ optional. If it's not present, deprecation warnings never become fatal. This should be a string in'YYYY-MM-DD'format or aDateTimeobject indicating when the deprecation warnings should become fatal.
die => '2009-06-06'
# or ...
die => DateTime->new( year => 2009, month => 06, day => 06 )
ifβ optional. May be a boolean value or a code reference.
if => ( @_ > 1 )
# or
if => sub { @_ > 1 }
If the 'if' condition evaluates to false, no deprecation action is taken. π«
If the 'if' argument is a code reference, it will receive the deprecate() argument list as a hash reference in $_[0], minus the 'if' key/value pair.
π PRODUCTION ENVIRONMENTS π
Don't break them. Just don't. People get mad at you and scratch you off their Christmas card list. ππ€
To ensure that Devel::Deprecate doesn't break production environments, deprecate() returns immediately if $ENV{HARNESS_ACTIVE} evaluates as false β thus ensuring that deprecations are generally only triggered by tests.
However, sometimes you might find this variable set in production code, so you can still disable this module by setting the $ENV{PERL_DEVEL_DEPRECATE_OFF} variable to a true value. π
Failing that, simply omit the die key. Then, at most you'll get lots of warnings and never a fatal error. π
π SCHEDULING DEPRECATIONS π
Typically you'll just want something like the following in your code:
deprecate( reason => 'Use CGI.pm instead of cgi-lib.pl' );
That issues noisy warnings about a deprecation, but at times you'll want to schedule a deprecation period. Maybe the deprecation won't even start until a new software package is installed in three months, and it's been agreed that the "old" interface is to be supported for six months. Assuming today is the first day of 2008, you might write a deprecation like this:
use Devel::Deprecate 'deprecate';
sub report : Path('/report/sales') {
deprecate(
reason => 'Pointy-haired bosses bought a reporting package',
warn => '2008-04-01',
die => '2008-10-01',
);
...
That subroutine should only run while testing (see PRODUCTION ENVIRONMENTS) and will likely annoy the heck out of developers with verbose error messages. Of course, that's the point. π The deprecation period, however, should be carefully thought through. In fact, you may wish to omit it entirely to ensure that the deprecation is never a fatal error.
Alternately, you might write it like this:
sub report : Path('/report/sales') {
deprecate(
reason => 'Pointy-haired bosses bought a reporting package',
die => '2008-10-01',
if => \&other_software_is_installed,
);
...
With this, the deprecation warnings begin if and only if the "other_software_is_installed" subroutine returns true. Further, even the "die" only goes off when that condition holds. π―
π«Ά AUTHOR π«Ά
Curtis "Ovid" Poe, "<ovid at cpan.org>" β king behavior honestly π
π BUGS π
Please report any bugs or feature requests to "bug-devel-deprecate at rt.cpan.org", or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel-Deprecate>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. we love a closed loop β¨
π SUPPORT π
You can find documentation for this module with the perldoc command.
perldoc Devel::Deprecate
You can also look for information at:
- RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Devel-Deprecate>
- AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/Devel-Deprecate>
- CPAN Ratings
<http://cpanratings.perl.org/d/Devel-Deprecate>
- Search CPAN
<http://search.cpan.org/dist/Devel-Deprecate>
π§ ACKNOWLEDGEMENTS π§
The "Refactoring Databases" book explained the rationale as to why we want automated deprecation periods. π
Several helpful comments on the Perl Monks discussion, particularly comments by Jenda about not breaking production code. π
π COPYRIGHT & LICENSE π
Copyright 2008 Curtis "Ovid" Poe, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
and that's the whole vibe check, bestie π this was theDevel::Deprecate(3)page, straight outtaperl v5.42.3, dated2026-08-10. go deprecate something responsibly, mwah πβ¨
π¦ where this page comes from
- fedora 43: perl-Devel-Deprecate 0.01-1.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- fedora 44: perl-Devel-Deprecate 0.01-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms