NAME

Perl::Critic::Policy::Freenode::DeprecatedFeatures - Avoid features that have been deprecated or removed from Perl

DESCRIPTION

While Perl::Critic::Policy::Freenode::StrictWarnings will expose usage of deprecated or removed features when a modern perl is used, this policy will detect such features in use regardless of perl version, to assist in keeping your code modern and forward-compatible.

FEATURES

:=

Because the whitespace between an attribute list and assignment operator is not significant, it was possible to specify assignment to a variable with an empty attribute list with a construction like my $foo := 'bar'. This is deprecated in perl v5.12.0 to allow the possibility of a future := operator. Avoid the issue by either putting whitespace between the : and = characters or simply omitting the empty attribute list.

$[

The magic "$[" in perlvar variable was used in very old perls to determine the index of the first element of arrays or the first character in substrings, and also allow modifying this value. It was discouraged from the start of Perl 5, its functionality changed in v5.10.0, deprecated in v5.12.0, re-implemented as arybase.pm in v5.16.0, and it is essentially a synonym for 0 under use v5.16 or no feature "array_base". While it is probably a bad idea in general, the modules Array::Base and String::Base can now be used to replace this functionality.

?PATTERN?

The ?PATTERN? regex match syntax is deprecated in perl v5.14.0 and removed in perl v5.22.0. Use m?PATTERN? instead.

autoderef

An experimental feature was introduced in perl v5.14.0 to allow calling various builtin functions (which operate on arrays or hashes) on a reference, which would automatically dereference the operand. This led to ambiguity when passed objects that overload both array and hash dereferencing, and so was removed in perl v5.24.0. Instead, explicitly dereference the reference when calling these functions. The functions affected are each, keys, pop, push, shift, splice, unshift, and values.

defined on array/hash

Using the function defined() on an array or hash probably does not do what you expected, and is deprecated in perl v5.6.2 and throws a fatal error in perl v5.22.0. To check if an array or hash is non-empty, test if it has elements.

if (@foo) { ... }
if (keys %bar) { ... }

do SUBROUTINE(LIST)

This form of do to call a subroutine has been deprecated since perl 5, and is removed in perl v5.20.0.

NBSP in \N{...}

Use of the "no-break space" character in character names is deprecated in perl v5.22.0 and an error in perl v5.26.0.

POSIX character functions

Several character matching functions in POSIX.pm are deprecated in perl v5.20.0. See the POSIX documentation for more details. Most uses of these functions can be replaced with appropriate regex matches.

isalnum, isalpha, iscntrl, isdigit, isgraph, islower, isprint, ispunct, isspace, issuper, isxdigit

POSIX::tmpnam()

The tmpnam() function from POSIX.pm is deprecated in perl v5.22.0 and removed in perl v5.26.0. Use File::Temp instead.

qr//xx

Use of multiple /x regular expression pattern modifiers on a single pattern is deprecated in perl v5.22.0 and an error in perl v5.26.0. This syntax previously had no extra effect.

qw(...) as parentheses

Literal parentheses are required for certain statements such as a for my $foo (...) { ... } construct. Using a qw(...) list literal without surrounding parentheses in this syntax is deprecated in perl v5.14.0. Wrap the literal in parentheses: for my $foo (qw(...)) { ... }.

UNIVERSAL->import()

The method UNIVERSAL->import() and similarly passing import arguments to use UNIVERSAL is deprecated in perl v5.12.0 and throws a fatal error in perl v5.22.0. Calling use UNIVERSAL with no arguments is not an error, but serves no purpose.

AFFILIATION

This policy is part of Perl::Critic::Freenode.

CONFIGURATION

This policy is not configurable except for the standard options.

CAVEATS

This policy is incomplete, as many deprecations are difficult to test for statically. It is recommended to use perlbrew or perl-build to test your code under newer versions of Perl, with warnings enabled.

AUTHOR

Dan Book, dbook@cpan.org

COPYRIGHT AND LICENSE

Copyright 2015, Dan Book.

This library is free software; you may redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

Perl::Critic