#!/usr/bin/perl ################################## # Check installed *CPAN* modules for COMMENTS! # # Because CPAN modules have a lot of COMMENTS! # # https://perlmonks.org/index.pl?node_id=1217408 # ################################################## use strict; use warnings; use Config '%Config'; use ExtUtils::Installed; for (split $Config{path_sep}, $ENV{PATH}) { $|++ if -x "$_/grep" } die "you need grep" unless $|; my $time = time; my $perl = ExtUtils::Installed->new; my @cpan = $perl->modules(); my @temp = (); for (@cpan) { my @cpan = $perl->files($_); push @temp, @cpan; } @cpan = grep /site.*\.pm$/, @temp; my $opt = 0; if (@ARGV) { $opt = 1 } else { print qq~Checking CPAN modules for COMMENTS in Perl versio~. qq~n $^V\n(Invoke with any arg to skip questions and gener~. qq~ate a list of modules.)\n\n~; print qq~The list may be big and printing progress makes i~. qq~t a bit slower.\nDefault: display progress, format outp~. qq~ut and print offending lines of code.\nPress return to ~. qq~start or n for no progress and list output. y/N~; chomp($opt = <STDIN>); $opt = 1 if $opt and lc $opt eq 'n'; } my $INC = join '|', @INC; my $acme = 0; my $grep = 0; for my $cpan (@cpan) { print "\rChecking: ","$acme\tFound: $grep\t" unless $opt; if(@_ =`grep '^#' $cpan`) { @_ = grep !/^#(pod|[\-=~\*]|[#]{5,}|\s*\n)/,@_; # FAKE next unless scalar @_; (my $name = $cpan) =~ s/($INC)//; $name =~ s,^/,,; $name =~ s,/,::,g; $name =~ s/\.pm$//; s/^\s+/ / for @_; $_{$name} = join "\n ", @_; $grep++ } $acme++ } if ($opt) { print "$_\n" for sort keys %_ } else { $perl = scalar keys %_; $time = time - $time; print qq~$perl CPAN modules (out of $acme) found with COMMENTS!\n~; print "$_:\n $_{$_}","-"x60,"\n" for sort keys %_; print qq~$perl CPAN modules (out of $acme) found with COMMENTS!\n~; print "That took $time secs (grep searched ",sprintf("%0d",$perl/$t +ime), " modules/sec).\n"; }
And had to find out how many modules are afflicted on my system (5.26.2):
905 CPAN modules (out of 4918) found with "use vars"!Output:#!/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 slow +er. 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 = <STDIN>); $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"; }
------------------------------------------------------------ XML::Twig: use vars qw($VERSION @ISA %valid_option); use vars qw( $weakrefs); use vars qw( %filter); ------------------------------------------------------------ XML::Twig::XPath: use vars qw($VERSION); ------------------------------------------------------------ YAPE::Regex: use vars '$VERSION'; ------------------------------------------------------------ YAPE::Regex::Explain: use vars '$VERSION'; ------------------------------------------------------------ 905 CPAN modules (out of 4918) found with "use vars"! That took 31 secs (grep searched 29 modules/second).
In reply to Check your CPAN modules for use vars by usemodperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |