package B::Lint;
our $VERSION = '1.02';
=head1 NAME
B::Lint - Perl lint
=head1 SYNOPSIS
perl -MO=Lint[,OPTIONS] foo.pl
=head1 DESCRIPTION
The B::Lint module is equivalent to an extended version of the B<-w>
option of B<perl>. It is named after the program B<lint> which carries
out a similar process for C programs.
=head1 OPTIONS AND LINT CHECKS
Option words are separated by commas (not whitespace) and follow the
usual conventions of compiler backend options. Following any options
(indicated by a leading B<->) come lint check arguments. Each such
argument (apart from the special B<all> and B<none> options) is a
word representing one possible lint check (turning on that check) or
is B<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:
=over 8
=item B<context>
Produces a warning whenever an array is used in an implicit scalar
context. For example, both of the lines
$foo = length(@bar);
$foo = @bar;
will elicit a warning. Using an explicit B<scalar()> silences the
warning. For example,
$foo = scalar(@bar);
=item B<implicit-read> and B<implicit-write>
These options produce a warning whenever an operation implicitly
reads or (respectively) writes to one of Perl's special variables.
For example, B<implicit-read> will warn about these:
/foo/;
and B<implicit-write> will warn about these:
Both B<implicit-read> and B<implicit-write> warn about this:
for (@a) { ... }
=item B<bare-subs>
This option warns whenever a bareword is implicitly quoted, but is also
the name of a subroutine in the current package. Typical mistakes that it will
trap are:
use constant foo => 'bar';
@a = ( foo => 1 );
$b{foo} = 2;
Neither of these will do what a naive user would expect.
=item B<dollar-underscore>
This option warns whenever $_ is used either explicitly anywhere or
as the implicit argument of a B<print> statement.
=item B<private-names>
This option warns on each use of any variable, subroutine or
method name that lives in a non-current package but begins with
an underscore ("_"). Warnings aren't issued for the special case
of the single character name "_" by itself (e.g. $_ and @_).
=item B<undefined-subs>
This option warns whenever an undefined subroutine is invoked.
This option will only catch explicitly invoked subroutines such
as C<foo()> and not indirect invocations such as C<&$subref()>
or C<$obj-E<gt>meth()>. Note that some programs or modules delay
definition of subs until runtime by means of the AUTOLOAD
mechanism.
=item B<regexp-variables>
This option warns whenever one of the regexp variables $', $& or
$' is used. Any occurrence of any of these variables in your
program can slow your whole program down. See L<perlre> for
details.
=item B<all>
Turn all warnings on.
=item B<none>
Turn all warnings off.
=back
=head1 NON LINT-CHECK OPTIONS
=over 8
=item B<-u Package>
Normally, Lint only checks the main code of the program together
with all subs defined in package main. The B<-u> option lets you
include other package names whose subs are then checked by Lint.
=back
=head1 BUGS
This is only a very preliminary version.
This module doesn't work correctly on thread-enabled perls.
=head1 AUTHOR
Malcolm Beattie, mbeattie@sable.ox.ac.uk.
=cut
use strict;
);
# Lint checks
my %check;
my %implies_ok_context;
BEGIN {
map($implies_ok_context{$_}++,
keys values hslice defined undef delete));
}
# Lint checks turned on by default
my @default_checks = qw(context);
my %valid_check;
# All valid checks
BEGIN {
map($valid_check{$_}++,
}
# Debugging options
my ($debug_op);
my %done_cv; # used to mark which subs have already been linted
my @extra_packages; # Lint checks mainline code and all subs which are
# in main:: or in one of these packages.
sub warning {
}
# This gimme can't cope with context that's only determined
# at runtime via dowantarray().
sub gimme {
my $op = shift;
}
return undef;
}
my $op = shift;
}
}
my $op = shift;
# Two special cases to deal with: "foreach (@foo)" and "delete $a{$b}"
# null out the parent so we have to check for a parent of pp_null and
# a grandparent of pp_enteriter or pp_delete
if ($pname eq "null") {
}
warning("Implicit scalar context for %s in %s",
}
if ($method =~ /^_/ && !defined(&{"$curstash\::$method"})) {
warning("Illegal reference to private method name $method");
}
}
}
}
my $op = shift;
if ($check{implicit_read}) {
warning('Implicit match on $_');
}
}
if ($check{implicit_write}) {
warning('Implicit substitution on $_');
}
}
}
my $op = shift;
warning('Implicit use of $_ in foreach');
}
}
}
}
my $op = shift;
{
}
}
{
warning('Use of $_');
}
if ($check{private_names}) {
}
} elsif ($opname eq "method_named") {
if ($method =~ /^_./) {
warning("Illegal reference to private method name $method");
}
}
}
if ($check{undefined_subs}) {
{
no strict 'refs';
if (!defined(&$subname)) {
}
}
}
if ($name =~ /^[&'`]$/) {
}
}
}
my $gv = shift;
#warn sprintf("lintcv: %s::%s (done=%d)\n",
# $gv->STASH->NAME, $gv->NAME, $done_cv{$$cv});#debug
#warn " root = $root (0x$$root)\n";#debug
}
sub do_lint {
my %search_pack;
# Now do subs in main
no strict qw(vars refs);
local(*glob);
next if $sym =~ /::$/;
}
# Now do subs in non-main packages given by -u options
my $package = shift;
$package =~ s/::$//;
#warn "Considering $package\n";#debug
return exists $search_pack{$package};
});
}
sub compile {
my @options = @_;
# Turn on default lint checks
for $opt (@default_checks) {
}
if ($option =~ /^-(.)(.*)/) {
$opt = $1;
$arg = $2;
} else {
last OPTION;
}
shift @options;
last OPTION;
} elsif ($opt eq "D") {
if ($arg eq "o") {
B->debug(1);
} elsif ($arg eq "O") {
$debug_op = 1;
}
}
} elsif ($opt eq "u") {
push(@extra_packages, $arg);
}
}
$opt =~ tr/-/_/;
if ($opt eq "all") {
%check = %valid_check;
}
elsif ($opt eq "none") {
%check = ();
}
else {
}
else {
}
}
}
# Remaining arguments are things to check
return \&do_lint;
}
1;