#!/usr/bin/perl ###################################### # Check installed CPAN modules for use of "use vars" # # Because Perl 5.28.0 removes discouraged "use vars" # # https://perlmonks.org/index.pl?node_id=1217408 # ###################################################### use strict; use warnings; use autodie; use Config '%Config'; use ExtUtils::Installed; for (split $Config{path_sep}, $ENV{PATH}) { $|++ if -x "$_/grep" } die "you need grep" unless $|; my $t = time; my $m = ExtUtils::Installed->new; my @temp = $m->modules(); my @cpan = (); for (@temp) { my @x = $m->files($_); push @cpan, @x; } @cpan = grep /site.*\.pm$/, @cpan; my $opt = 0; if (@ARGV) { $opt = 1 } else { print qq~Checking CPAN modules for "use vars" in Perl version $^V ~. qq~(removed in Perl 5.28)\nhttps://metacpan.org/pod/release/XSAWYE~. qq~RX/perl-5.28.0/pod/perldelta.pod#Removal-of-use-vars \n(Invoke~. qq~ with any arg to skip questions and generate a list of modules.) \n\n~; print qq~The list may be big and printing progress makes it a bit slower. Default: display progress, format output and print offending lines of code. Press return to start or n for no progress and list output. y/N~; chomp($opt = ); $opt = 1 if $opt and lc $opt eq 'n'; } my $INC = join '|', @INC; my $n = 0; my $g = 0; for my $c (@cpan) { print "\rChecking: ","$n\tFound: $g\t" unless $opt; if (@_ = `grep 'use vars' $c`) { (my $f = $c) =~ s/($INC)//; $f =~ s,^/,,; $f =~ s,/,::,g; $f =~ s/\.pm$//; s/^\s+/ / for @_; $_{$f}=join"\n ",@_; $g++ } $n++ } if ($opt) { print "$_\n" for sort keys %_ } else { $m = scalar keys %_; $t = time - $t; print qq~$m CPAN modules (out of $n) found with "use vars"!\n~; print "$_:\n $_{$_}","-"x60,"\n" for sort keys %_; print qq~$m CPAN modules (out of $n) found with "use vars"!\n~; print "That took $t secs (grep searched ",sprintf("%0d",$m/$t), " modules/second).\n"; }