Created
December 6, 2011 17:00
-
-
Save Ovid/1438952 to your computer and use it in GitHub Desktop.
Rerun perl -c with warnings unused
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use Modern::Perl; | |
use File::Temp 'tempfile'; | |
use IO::All; | |
my $libcustom = '.libcustom'; | |
# run the code with perl -c and show STDERR if it fails. Otherwise, rerun it | |
# with perl -c -Mwarnings::unused | |
my $prog = shift // die "Usage: $0 perlfile"; | |
my $PERL5LIB = $ENV{PERL5LIB} // ''; | |
if ( -f $libcustom ) { | |
chomp( my @libs = io($libcustom)->slurp ); | |
$PERL5LIB = join ':' => $PERL5LIB, @libs; | |
} | |
my ( undef, $tempfile ) = tempfile(); | |
my $perl = "PERL5LIB=$PERL5LIB perl "; | |
my $command = "$perl -c $prog 2>$tempfile 1>$tempfile"; | |
# if anything goes to STDERR by the program completes successfully, don't show | |
# anything because we're going to rerun with warnings::unused and we don't | |
# need to duplicate the messages to STDERR | |
my $error = system($command); | |
$error and do { | |
print io($tempfile)->slurp; | |
exit $error; | |
}; | |
$command = "$perl -Mwarnings::unused -MVi::QuickFix -c $prog"; | |
system($command); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment