B::FindAmpersand - A compiler backend to find variables that set sawampersand


Devel-SawAmpersand documentation Contained in the Devel-SawAmpersand distribution.

Index


Code Index:

NAME

Top

B::FindAmpersand - A compiler backend to find variables that set sawampersand

SYNOPSIS

Top

 perl -MO=FindAmpersand file.pl

DESCRIPTION

Top

The Devel::SawAmpersand can tell you if Perl has set sawampersand, but it doesn't tell you where. Sure, you can grep, but what if you don't know where to grep?

AUTHOR

Top

Doug MacEachern

LICENSE

Top

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See http://www.perl.com/perl/misc/Artistic.html


Devel-SawAmpersand documentation Contained in the Devel-SawAmpersand distribution.

package B::FindAmpersand;
BEGIN {
  require Config;
  die "B::FindAmpersand not supported for threaded perl" if $Config::Config{usethreads};
}

use B;
use strict;
use vars qw($VERSION);

$VERSION = "0.04";

my $evil = join "", qw"[ ` & ' ]";

sub compile {
    return sub { B::walkoptree(B::main_root(), "findampersand") }
}

sub B::GVOP::findampersand {
    my($op, $level) = @_;
    $op->gv->findampersand($op);
}

sub B::GV::findampersand {
    my($gv) = @_;
    return unless $gv->NAME =~ /^$evil$/;
    my @report = ($gv->NAME, $gv->FILEGV->SV->PV, $gv->LINE);
    warn sprintf "Found evil variable \$%s in file %s, line %s\n", @report;
}

sub B::OP::findampersand {}
*B::SVOP::findampersand = $] < 5.006 ? sub {} : sub {
    shift->gv->findampersand;
};
sub B::PMOP::findampersand {}
sub B::PVOP::findampersand {}
sub B::COP::findampersand {}
sub B::PV::findampersand {}
sub B::AV::findampersand {}
sub B::IV::findampersand {}
sub B::NV::findampersand {}
sub B::NULL::findampersand {}
sub B::SPECIAL::findampersand {}

1;

__END__