Do not use deprecated or obsolescent functions when more secure equivalent functions are available.

Here is a list of deprecated functions along with their recommended alternatives if available:

Deprecated

Preferred

die()

Carp::croak()

warn()

Carp::carp()

-t

IO::Interactive

format()

Template, Perl6::Form

The following modules are also deprecated:

Deprecated

Preferred

base

parent

Noncompliant Code Example (die())

This noncompliant code example tries to open a file and invokes the obsolete die() method if it fails.

my $file;
open(FILE, "<", $file) or die "error opening $file: stopped";
# work with FILE

The die() method is considered deprecated because it prints the file name and line number in which it was invoked. This information might be sensitive.

Compliant Solution (croak())

This compliant solution uses the croak() function instead of die().

use Carp;

my $file;
open(FILE, "<", $file) or croak "error opening $file: stopped";
# work with FILE

Unlike die(), croak() provides the file name and line number of the function that invoked the function that invoked croak(). This solution is more useful for application code that invokes library code; in this case, croak() and carp() also will reveal the file name and line number of the application code rather than the library code.

Exceptions

EXP30:EX0: The -t function should not be used for determining if input is interactive, but it is perfectly valid to determine if output is interactive. So it may be used on *STDOUT or *STDERR.

EXP30:EX1: There are several instances when die() and warn() are preferred over carp() and croak():

Risk Assessment

Using deprecated or obsolete classes or methods in program code can lead to erroneous behavior.

Recommendation

Severity

Likelihood

Remediation Cost

Priority

Level

EXP30-PL

Medium

Probable

Low

P12

L1

Automated Detection

Tool

Diagnostic

Perl::Critic

 

 

ErrorHandling::RequireCarping

InputOutput::ProhibitInteractiveTest

Miscellanea::ProhibitFormats

Related Guidelines

SEI CERT C Coding StandardMSC24-C. Do not use deprecated or obsolescent functions
CERT Oracle Secure Coding Standard for JavaMET02-J. Do not use deprecated or obsolete classes or methods

Bibliography

[Conway 2005] 
[CPAN]Elliot Shank, Perl-Critic-1.116 RequireCarping, InteractiveTest, ProhibitFormats
[CPAN]Chris Dolan, base
[CPAN]Max Maischein, parent