B::Lint(3pm) | User Contributed Perl Documentation | B::Lint(3pm) |
B::Lint - Perl lint
perl -MO=Lint[,OPTIONS] foo.pl
The B::Lint module is equivalent to an extended version of the -w option of perl. It is named after the program lint which carries out a similar process for C programs.
Option words are separated by commas (not whitespace) and follow the usual conventions of compiler backend options. Following any options (indicated by a leading -) come lint check arguments. Each such argument (apart from the special all and none options) is a word representing one possible lint check (turning on that check) or is no-foo (turning off that check). Before processing the check arguments, a standard list of checks is turned on. Later options override earlier ones. Available options are:
% touch 'rm *|' % perl -pe 1
The above creates a file named "rm *|". When perl opens it with "<>" it actually executes the shell program "rm *". This makes "<>" dangerous to use carelessly.
$foo = length(@bar); $foo = @bar;
will elicit a warning. Using an explicit scalar() silences the warning. For example,
$foo = scalar(@bar);
/foo/;
and implicit-write will warn about these:
s/foo/bar/;
Both implicit-read and implicit-write warn about this:
for (@a) { ... }
use constant foo => 'bar'; @a = ( foo => 1 ); $b{foo} = 2;
Neither of these will do what a naive user would expect.
Notice: Perl 5.22.0 does not report "foo" in $b{foo} as BARE token anymore. Therefore B::Lint test is not reliable here. See CPAN RT#101115 <https://rt.cpan.org/Public/Bug/Display.html?id=101115>.
Lint can be extended by with plugins. Lint uses Module::Pluggable to find available plugins. Plugins are expected but not required to inform Lint of which checks they are adding.
The "B::Lint->register_plugin( MyPlugin => \@new_checks )" method adds the list of @new_checks to the list of valid checks. If your module wasn't loaded by Module::Pluggable then your class name is added to the list of plugins.
You must create a "match( \%checks )" method in your plugin class or one of its parents. It will be called on every op as a regular method call with a hash ref of checks as its parameter.
The class methods "B::Lint->file" and "B::Lint->line" contain the current filename and line number.
package Sample; use B::Lint; B::Lint->register_plugin( Sample => [ 'good_taste' ] ); sub match { my ( $op, $checks_href ) = shift @_; if ( $checks_href->{good_taste} ) { ... } }
This is only a very preliminary version.
Malcolm Beattie, mbeattie@sable.ox.ac.uk.
Sebastien Aperghis-Tramoni - bug fixes
2022-11-19 | perl v5.36.0 |