You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 11 Next »

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

Class::ISA

Pod::Plainer

Shell

Switch

Universal::isa

Universal::can

Universal::VERSION

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();
  }
  # ...
}

While this code works correctly now, the use statement will one day not be accepted by the Perl interpreter.

Compliant Solution (Universal::can())

This compliant solution uses Universal::can() without explicitly importing it.

# use UNIVERSAL qw(can);  # deprecated

# ... rest of code

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

P6

L2

Automated Detection

Tool

Diagnostic

Perl::Critic

Modules::ProhibitEvilModules

 

BuiltinFunctions::ProhibitUniversalCan

 

BuiltinFunctions::ProhibitUniversalIsa

-w

... 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


  • No labels