Despite being over 15 years old, Perl 5 continues to grow. Much of this growth comes from Perl's practice of assimilating CPAN modules that prove to be popular. Modules that are not part of Perl must be explicitly included to be used by a program, but modules that are part of the core language need not be.
When a module has been assimilated into the language, the original module is still available in CPAN, but its use is deprecated. Do not import deprecated modules. It is perfectly valid to use their features, as they are now integrated into the core language.
Here is a list of CPAN modules that are deprecated, according to Perl::Critic.
Deprecated |
---|
|
|
|
|
|
|
|
Noncompliant Code Example (Universal::can()
)
This noncompliant code example tries to see if an object supports a method. The Universal::can()
method provides this capability. It was formerly an external CPAN module, but it is now part of Perl itself.
use UNIVERSAL qw(can); # deprecated # ... sub doit { my ($func) = @_; if (can($self, $func)) { $self->$func(); } # ... }
Although this code works correctly now, the use
statement will one day not be accepted by the Perl interpreter.
Compliant Solution
This compliant solution uses Universal::can()
without explicitly importing it.
# use UNIVERSAL qw(can); # deprecated # ... sub doit { my ($func) = @_; if (can($self, $func)) { $self->$func(); } # ... }
Risk Assessment
Using deprecated or obsolete classes or methods in program code can lead to erroneous behavior.
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
DCL30-PL | Medium | Likely | Low | P18 | L1 |
Automated Detection
Tool | Version | Checker | Description |
---|---|---|---|
Perl::Critic | 5.0 | Modules::ProhibitEvilModules | Implemented |
B::Lint | 5.0 | ... is deprecated and will be removed in a future ... |
Bibliography
[CPAN] | Elliot Shank, Perl-Critic-1.116 Modules::ProhibitEvilModules, ProhibitUniversalCan, ProhibitUniversalIsa |
[CPAN] | Ragwitz, Florian, UNIVERSAL |